I am getting different ans in top down and in bottom up dp

if(n%3==0){
x=top(n/3,d)+1;
}
if(n%2==0){
y=top(n/2,d)+1;
}
z=top(n-1,d)+1;
int ans=min(min(x,y),z);

this will work fine now
if this solves your doubt please mark it as resolved :slight_smile:

again different answers are coming

check this


i have made the correction