value. In one step you may:
- halve the number if it is even;
- add 1 to it or subtract 1 from it (your choice) if it is odd.
Return the smallest number of steps needed to turn value into 1.value=12 → 4
12 → 6 → 3 → 2 → 1: four steps.
value=15 → 5
15 → 16 → 8 → 4 → 2 → 1: adding one beats subtracting here.
value=1 → 0
The number is already 1, so no steps are needed.
value ≤ 2³¹ − 1value=12
4
Run checks the first 3 tests in your browser. Submit checks all 40 tests on the server, hidden ones included.