Wrong answer in dp code

Why am I getting the wrong answer in all the test cases?

hello @kunal81198
pls share ur code using cb ide

@kunal81198
image
a)initialisation is not correct, because we have to find minimum so u need to intialise ur dp state with INT_MAX or some very big number

b) run the inner loop only when dp[i]!=INT_MAX or ur initilaised value.

c) inside inner for loop
simply do
dp[i+k]=min(dp[i]+1,dp[i+k]) // no need of if -else

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.