Minimum Numeric Code Transformation
Problem statement
You receive one reconfiguration request. Start with the positive integer x and transform it into y. Each allowed operation costs exactly one step:
- Scale: choose an integer
awith2 <= a <= kand replace the current valuevwithv * a, only when the result is at most10^6. - Split: choose an integer
awith2 <= a <= k. Ifvis divisible bya, replace it withv / a. - Mirror: reverse the decimal digits. Leading zeros produced by reversal are discarded, so
120becomes21. - Rotate last to front: move the final decimal digit to the front. This operation is forbidden when it would create a leading zero.
- Swap adjacent digits: swap any one adjacent pair. This operation is forbidden when it would create a leading zero.
Every intermediate value must remain between 1 and 10^6, inclusive. Return the minimum number of operations needed to reach y, or -1 when no valid sequence exists.
Function
minimumCodeTransformOperations(x: int, y: int, k: int) → intExamples
Example 1
x = 4y = 6k = 3return = 2Scale by 3 to get 12, then split by 2 to get 6. No one-step operation transforms 4 directly into 6.
Example 2
x = 120y = 21k = 10return = 1One mirror operation reverses 120 to 021; the leading zero is discarded, leaving 21.
Constraints
1 <= x, y <= 10^62 <= k <= 10^3
Source note: Public assessment screenshots showing the complete operation rules, bounds, and sample.