Broken calculator problem on Leetcode

On a broken calculator that has a number showing on its display, we can perform two operations:

Double: Multiply the number on the display by 2, or;

Decrement: Subtract 1 from the number on the display.
Initially, the calculator is displaying the number X.

Return the minimum number of operations needed to display the number Y.

this is a question on leetcode and i have written a solution for it which is not working, can you please tell me what is wrong in my code?

Your X should ultimately converge to Y.
Your code is calling the function for 2*X and X-1.

If X = 2,Y=3, you will calculate for(4,3) and (1,3)
then (4,3) would terminate and (1,3) would call (2,3)
(2,3) —> -->–>--> (2,3)
this will occur infinitely many times until the call stack overflows.

then what should be done?

Either you can do it backwards, as you might have seen in the videos as well, or you can try making a visited arr, and keep a track of values of X that you have visited because visiting the same value of X again won’t fetch you anything.