Minimum Operations with Multiply by Two and Divide by Three
Problem statement
Start at integer 1. Operation * replaces x with 2x; operation / replaces x with floor(x/3). Every intermediate state must remain between 1 and maxState.
Return a shortest operation string reaching target. Break shortest ties lexicographically with * before /. Return IMPOSSIBLE when unreachable.
Function
shortestOperationSequence(target: int, maxState: int) → StringExamples
Example 1
target = 10maxState = 16return = "****/*"1->2->4->8->16->5->10.
Example 2
target = 3maxState = 16return = "****/*/"The source's example reaches 3 through 16,5,10,3.
Constraints
1 <= target <= maxState <= 10^6.