Minimum Steps with Double and Floor-Divide
Problem statement
Start with the integer 1. In one step, replace the current value x with either:
x * 2, orfloor(x / 3).
Given target, return the minimum number of steps needed to reach it.
Function
minStepsToTarget(target: int) → intExamples
Example 1
target = 1return = 0The starting value already equals the target.
Example 2
target = 5return = 5One shortest sequence is 1 -> 2 -> 4 -> 8 -> 16 -> 5.
Example 3
target = 3return = 7A shortest sequence is 1 -> 2 -> 4 -> 8 -> 16 -> 32 -> 10 -> 3.
Constraints
0 <= target <= 100- All intermediate values are represented with signed 64-bit integers.
- Every target in the allowed range is reachable.