Count the Forced Halve-or-Decrement Steps
Company: Google
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: easy
Interview Round: Other
### Problem
Reduce num to 0. At every nonzero even value, divide by 2; at every odd value, subtract 1. Return how many forced operations are performed.
```cpp
class Solution {
public:
int numberOfSteps(int num);
};
```
### Examples
**Example 1:**
```text
Input: num = 6
Output: 4
Explanation:6->3->2->1->0 uses four steps.
```
**Example 2:**
```text
Input: num = 0
Output: 0
Explanation: The target is already reached.
```
### Constraints
- num is an integer in `[0,1000000]`.
### Contract considerations
Input may be 0 and is never negative.
```hint Read the boundary condition
Check zero input and both parity cases under the prescribed operation rule. The output counts operations rather than intermediate values.
```
### Boundary reminders
Input may be 0 and is never negative.
Overview: Count the Forced Halve-or-Decrement Steps. Reduce num to0. At every nonzero even value, divide by2; at every odd value, subtract1.