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 x by 11 if x is a multiple of 11.
  • Divide x by 5 if x is a multiple of 5.
  • Decrement x by 1.
  • Increment x by 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
Transform x=26 to y=1 with Minimum OperationsStart26÷55÷51Target1Op 1Op 2Operations Available:• Divide by 11 (if divisible) • Divide by 5 (if divisible)• Increment by 1 • Decrement by 1Answer: 2 operations (26 → 5 → 1)
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
Asked in
Google 23 Amazon 18 Meta 15
32.4K Views
Medium Frequency
~15 min Avg. Time
876 Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen