🚀 Day 1 of My Coding Journey | GeeksforGeeks
Hello developers 👋
This is Sabarish M S from Government College of Engineering, Salem, Tamil Nadu, India 🇮🇳.
I’ve officially started my coding journey with GeeksforGeeks, and this is Day 1.
🔹 Problem Statement
Given a positive integer n, determine whether it is odd or even.
Return true if the number is even
Return false if the number is odd
🔹 Examples
Input: n = 15
Output: false
Explanation: 15 is not divisible by 2, so it is an odd number.
Input: n = 44
Output: true
Explanation: 44 is divisible by 2, so it is an even number.
🔹 Constraints
1 ≤ n ≤ 10⁴
🔹 Solution Approach (Bitwise Logic)
Instead of using the modulus operator, I used a bitwise approach, which is both efficient and elegant.
💡 Key Insight:
In binary representation:
Even numbers always end with 0
Odd numbers always end with 1
🔧 How it works:
Perform a bitwise AND operation with 1
n & 1
If the result is 0 → the number is even
If the result is 1 → the number is odd
This works because the least significant bit (LSB) determines the parity of a number.
🔹 Why Bitwise?
✅ Faster than modulo
✅ Low-level understanding
✅ Frequently asked in interviews
✅ Clean and elegant logic
Top comments (0)