dsa · medium
Convert M to N (min -1 and *2)
GreyOrangeGraphQueue
Start at integer m. Operations: subtract 1, or multiply by 2. Return the minimum operations to reach n.
Arguments
m— the starting integern— the target integer
**Example:** m=4, n=6 → 2 (4-1=3, 3*2=6).
Constraints
1 <= m, n <= 4*10^4 Hidden tests include near-max size for this bound; a slower-than-intended solution TLEs.
Examples
Example 1
Input: 4 6 Expected: 2
Example 2
Input: 3 3 Expected: 0