Given a positive integer n, return the minimum number of replacements needed to reduce n to 1. Pattern focus: Isolate Lowest Bit. Odd numbers must be nudged using +1 or -1 based on low-bit structure, while even numbers are shifted right.
n = positive integer
minimum number of replacements to reduce n to 1
Example 1:
Input:
n = 8
Output:
3
Explanation:
8 -> 4 -> 2 -> 1 takes three steps.
Example 2:
Input:
n = 7
Output:
4
Explanation:
One optimal path is 7 -> 8 -> 4 -> 2 -> 1.