Number of Steps to Reduce a Number to Zero - Problem
Given an integer num, return the number of steps to reduce it to zero.
In one step, if the current number is even, you have to divide it by 2, otherwise, you have to subtract 1 from it.
Input & Output
Example 1 — Basic Case
$
Input:
num = 14
›
Output:
6
💡 Note:
Step-by-step: 14 → 7 → 6 → 3 → 2 → 1 → 0. Total of 6 steps.
Example 2 — Small Number
$
Input:
num = 8
›
Output:
4
💡 Note:
8 → 4 → 2 → 1 → 0. All even numbers except the last step.
Example 3 — Edge Case
$
Input:
num = 1
›
Output:
1
💡 Note:
Only one step needed: 1 → 0
Constraints
- 0 ≤ num ≤ 106
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code