Minimum Number of Operations to Make X and Y Equal

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.

Example 1
Inputx = 26, y = 1
Output3
By decrementing 26 to 25, then dividing by 5 twice, 26 becomes 1 in 3 operations, which is the minimum.
Example 2
Inputx = 54, y = 2
Output4
By incrementing 54 to 55, dividing by 11, dividing by 5, and incrementing once, 54 becomes 2 in 4 operations, which is the minimum.

Constraints

  • 1 <= x, y <= 10^4

Asked at 2 companies

</>

Your Solution

(Ctrl/Cmd + Enter)

Switching Language

Loading template...

Loading...

Sign in to save your progress

AI code evaluation

Get a correctness verdict, missed edge cases, and complexity analysis of your solution.

Sign in to evaluate