Regarding correction in the Code

#include<bits/stdc++.h>

using namespace std;

int minSteps(int n , int dp[])
{

dp[0] = 0;
dp[1] = 0;
for (int i = 2; i <=n; ++i) {
    if(i%2==0)
    {
        dp[i] =min(dp[i/2] , dp[i-1]) + 1;
    }
    else if(i%3==0)
    {
        dp[i] = min(dp[i/3] , dp[i-1]) + 1;
    }
    else
    {
        dp[i] = dp[i-1] + 1;
    }
}
return dp[n];

}

int main() {

int n;
cin >> n;
int dp[10005] = {0};
cout<<minSteps(n, dp);

}

//What is wrong in the above code for minimum steps to one ? It is giving wrong answer for n = 30;

dp[i]=dp[i-1]+1;
if(i%2==0)dp[i]=min(dp[i],dp[i/2]+1);
if(i%3==0)dp[i]=min(dp[i],dp[i/3]+1);

This should be the correct way

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.