Ctrl K

Inverted Binary Digits

Easy
Write the positive integer value in binary with no leading zeros, then turn every 1 in that string into a 0 and every 0 into a 1. Return the resulting number.
Example 1
value=12 → 3

12 is 1100. Inverted, it becomes 0011, which is 3.

Example 2
value=7 → 0

7 is 111; every bit turns into 0, so the answer is 0.

Example 3
value=18 → 13

18 is 10010 → 01101, which is 13.

Constraints
  • 1 ≤ value < 2³¹
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
value=12
Expected
3

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