Minimum Number of Operations to Make X and Y Equal - Problem
You are given two positive integers x and y. In one operation, you can do one of the four following operations:
- Divide
xby 11 ifxis a multiple of 11. - Divide
xby 5 ifxis a multiple of 5. - Decrement
xby 1. - Increment
xby 1.
Return the minimum number of operations required to make x and y equal.
Input & Output
Example 1 — Basic Division
$
Input:
x = 26, y = 1
›
Output:
2
💡 Note:
26 → 5 (divide by 5) → 1 (divide by 5). Total: 2 operations.
Example 2 — Already Equal
$
Input:
x = 54, y = 54
›
Output:
0
💡 Note:
x and y are already equal, so no operations needed.
Example 3 — Increment Strategy
$
Input:
x = 25, y = 30
›
Output:
5
💡 Note:
Since y > x, we can only increment: 25 → 26 → 27 → 28 → 29 → 30. Total: 5 operations.
Constraints
- 1 ≤ x, y ≤ 104
- Both x and y are positive integers
Visualization
Tap to expand
Understanding the Visualization
1
Input
x = 26, y = 1, find minimum operations
2
Process
Choose optimal sequence: ÷5, ÷5
3
Output
Minimum operations = 2
Key Takeaway
🎯 Key Insight: Division operations can make large jumps, so explore all possibilities with memoization for optimal efficiency
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code