Minimum steps botton cpp


the bottom up and top down approach are not giving same output.(eg:-5)

Hello Kushagra, your code is absolutely right just a small mistake.

        if (n % 3 == 0)
        {
            op1 = dp[i / 3];
        }
        if (n % 2 == 0)
        {
            op2 = dp[i / 2];
        }

In bottom-up function you have written this. Here what you have done is checked the conditions by using n%3 == 0 or n%2 == 0 but instead of n there must be i that means the current state not for the final state.
So just replace n with i in these conditions.

        if (i % 3 == 0)
        {
            op1 = dp[i / 3];
        }
        if (i % 2 == 0)
        {
            op2 = dp[i / 2];
        }

Now it will work.
I hope it is clear to you. In case it is clear to you pls mark it as resolve and provide the rating as well as feedback so that we can improve ourselves.
In case there is still some confusion pls let me know, I will surely try to help you out.
Thanks :slight_smile:
Happy Coding !!

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.