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
Understanding the Visualization
1
Input
Start with integer num = 14
2
Process
Apply rules: even ÷ 2, odd - 1
3
Output
Count total steps = 6
Key Takeaway
🎯 Key Insight: Each bit in the binary representation contributes to the step count
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code