how did you get 36 here?

in approach 2

1 Like

Input -

x=5 , y=41

Difference = 36

So, 36 is maximum number of steps needed to achieve 41 from 5 (just add '1' 36 times)

what would be minimum number of steps?You will obviously minimize 36 to an extent which is possible.

Understood?

1 Like

Can you please explain, for x<y, if the difference is even and it will be not divisible by 2… how can we moves in 2 steps?

you can’t do that in 2 steps it will take 3 because even +odd(a) -even(b)=odd so never gonna get 10 or would you explain if something Is wrong with my explanation for x=2 and y=10

Sure.

For X = 4 , Y = 10, add 3 twice, So min steps = 2

For X = 2 , Y = 10, add 5 twice. So min steps = 2