Understand
30-second explanation
Build the interview-ready mental model before comparing implementations.
Return `(n & 1) == 0`. The lowest bit being 0 means the number is even — works for negatives in two's-complement too.
Interview contextWhat is testedWhere candidates slipHow to stand outExplore interview contextHide interview context
What's being tested
Whether you know parity lives in the low bit and why AND is robust.
Where candidates slip
Falling back to modulo, or the negative-modulo trap.
How to stand out
Explain why only the 2⁰ bit affects parity.
Choose
Compare the available approaches
Use constraints and trade-offs to select the route you can defend in an interview.
Learn & trace
Build each solution step by step
Move from the core idea to a visual trace, implementation, proof, and edge cases.
Approach 1 of 1 · Optimal
Lowest-bit parity test
1Hint 1Explore hintHide hint
Which single bit determines whether a number is even or odd?
2Hint 2Explore hintHide hint
AND with 1 to isolate it.
3Hint 3Explore hintHide hint
Why is this more robust than `% 2` for negatives?
A · Core idea
Decide parity with the lowest bit: n & 1 is 0 for even numbers and 1 for odd, so (n & 1) == 0 tests evenness without the modulo operator.
Why the last bit decides parity. In binary, every bit above position 0 contributes a multiple of 2 (always even). Only the 2⁰ bit can make a number odd. ANDing with 1 keeps just that bit, so the result is the parity.
Why it's safer than `%` for negatives. In Java/C++ n % 2 can be -1 for negative odd numbers, which trips up == 1 checks. n & 1 reads the actual low bit and is 1 for negative odds too (two's complement), so the parity test is robust.
Performance. A single AND is as cheap as it gets — equivalent to % 2 but the question specifically asks for the bitwise form.
B · Visual dry run
Interactive dry run
Select a frame to connect the decision with its visual state.
n = 7, then n = 47 & 1
111 & 001 = 1
odd7 → false, 4 → trueC · Code with teaching comments
D · Why it works and complexityO(1) timeO(1) spaceOpen the invariant and proofExplore the proofHide the proof
ComplexityO(1) time, O(1) space — one bitwise AND — constant time.
E · Edge cases and pitfalls5n = 0 — 0 & 1 = 0 → even.Explore edge casesHide edge cases
Edge cases handled
n = 00 & 1 = 0 → even.n = -3Low bit 1 → odd (robust for negatives).n = -4Low bit 0 → even.
Pitfalls
- Using `n % 2 == 0` when the question asks for bitwise.
- Assuming negatives behave like `%` (they don't always).
Practice
Try the solution yourself
Edit the optimal implementation, test another input, and observe the result.
Editable code previewpublic boolean isEven(int n) { return (n & 1) == 0; }Explore the playgroundClose the playground
Avoid mistakes
Recognize the interview traps
Understand why common attempts fail before reviewing the corrected implementation.
- Using `n % 2 == 0` when the question asks for bitwise.
- Assuming negatives behave like `%` (they don't always).
Revise
Carry the pattern into the interview
Pattern to remember
n & 1 parity
Code pattern to memorize
(n & 1) == 0 -> evenRules to remember
- 1Lowest bit = parity.
- 2n & 1 == 0 → even.
- 3Safe for negatives.
Use this pattern when
- Parity without modulo
- Bit-level checks
Interview takeaway
n & 1 reads parity from the last bit, no modulo needed.
Continue
Transfer the pattern to another problem
Use a direct variation or pattern sibling to prove the idea is reusable.
Transferable patternA core fresher pattern: n & 1 parity. Master it on small inputs and it transfers to harder problems.
Practice queueDirect variations and pattern siblings
Direct follow-ups