Steps to Reduce to Zero
In one step, if the current number is even divide it by 2, otherwise subtract 1. Return how many steps it takes to reach 0 starting from num.
Example 1
num 14
returns 6
14, 7, 6, 3, 2, 1, 0: six steps.
Example 2
num 0
returns 0
Already zero.
Constraints
0 <= num <= 10**6
Write it in your browser, against the clock. The model solution, stepped through line by line, comes after.
More Math problems
- Sum of Consecutive PowersBeginner
- Sum of DivisorsBeginner
- Sum of MultiplesBeginner
- Type of TriangleBeginner
- Add Minutes to a ClockEasy
- Add StringsEasy
- Add Two Numbers in Base KEasy
- Angle Between Clock HandsEasy