Getting wrong output.
Whats wrong in my approach?
hello @Prashant-Kumar-1947183015386369
use long long here
also use modulo property to perform addition.
dp[i]=(dp[i-1]%mod + dp[i-2]%mod)%mod;
Hi Aman, I have #defined int as long long
PS : Even after modulo division it fails 2 test cases
handle when n==1 then ur dp size will be 2.and u will try to acccess index 2. which is wrong.
so handle this case separately .
i.e if n <=2 return n.
Still 2 test cases show run error
pls share ur updated code.
and problem link.
declare ur dp array as global array of constant size and then try.
Now getting MLE in one tc
ok ,so see dp[i] depends on previous two states only i.e dp[i-1] and dp[i-2].
so instead of using array use two variable to store previous 2 states.
use mod property here as well
Thank you very much.