Ctrl K

Next All-Ones Number

Easy
You get a positive integer num. Return the smallest number that is at least num and whose binary form is made up of ones only.
Example 1
num=9 → 15

9 is 1001 in binary. The nearest all-ones number is 1111, which is 15.

Example 2
num=31 → 31

31 is 11111 in binary, already all ones.

Example 3
num=2 → 3
Constraints
  • 1 ≤ num ≤ 1000
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsSum of Binary Strings EasyOnly Twos Multiplied EasyThe Lost Ticket EasyOnly Fours Multiplied EasyHexadecimal Notation Easy
loading Python…
Input
num=9
Expected
15

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