Dsa
Bit Manipulation
Medium
Flip to Make Even
You are given an integer n. Your task is to flip the least significant bit of n to make it even. If n is already even, return n. If n is odd, return n + 1.
Input:
A single integer n (0 <= n <= 10^6).
Output:
An integer representing the new value of n after flipping.
Example:
Input:
7
Output:
8
Explanation:
7 is odd, flipping the least significant bit would make it 8, which is even.
Key concepts
bit manipulationeven/oddconditional operations
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now