Ctrl K

Flip Every Bit

Easy
You get a non-negative integer num. Write it in binary without leading zeros, turn every 0 into a 1 and every 1 into a 0, and return the resulting number as a regular integer. Zero is written as the single digit 0.
Example 1
num=12 → 3

12 is 1100 in binary. Flipping every bit gives 0011, which is 3.

Example 2
num=1 → 0

1 is a single one bit; flipped, it becomes 0.

Example 3
num=0 → 1

Zero is written as a single 0 digit, which flips to 1.

Constraints
  • 0 ≤ num < 10⁹
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsSum of Binary Strings EasyThe Unpaired Value EasyFlip the Bit Order EasyCount the Set Bits EasySize of a Packed Tree Easy
loading Python…
Input
num=12
Expected
3

Run checks the first 3 tests in your browser. Submit checks all 36 tests on the server, hidden ones included.