Minimum step bottom up

in this question i should get 3 as output for input 5 but through this code i am getting output as 4.
here is the code


this is the same code as taught in this video
i think in place of n it should be i please check and guide

Check now. In place of n, it must be i there