Minimize operations to reduce integer to zero
Company: Salesforce
Role: Software Engineer
Category: Coding & Algorithms
Difficulty: medium
Interview Round: Onsite
You are given a non-negative integer `n`.
In **one operation**:
- If `n` is even, you may replace `n` with `n / 2`.
- If `n` is odd, you may replace `n` with either `n + 1` or `n - 1`.
Return the **minimum number of operations** needed to make `n = 0`.
### Input
- A single integer `n`.
### Output
- An integer: the minimum number of operations to reach `0`.
### Constraints
- Assume `0 <= n <= 10^9` (or similar large bound).
### Examples
- `n = 0` → `0`
- `n = 7` → `5` (one optimal path: 7→8→4→2→1→0)
Quick Answer: This question evaluates algorithmic problem-solving and integer-manipulation skills, specifically assessing the ability to reason about operation counts and binary behavior, and it belongs to the Coding & Algorithms category.