Whats wrong in my approach?

Getting wrong output.

hello @Prashant-Kumar-1947183015386369
image

use long long here image

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.

https://online.codingblocks.com/app/player/42595/content/83730/5073/code-challenge

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.

Now what is the problem? https://ide.codingblocks.com/s/247031

image
use mod property here as well

Thank you very much.