K Fibonacci Problem Code : KFIB

Can someone tell me for what test-cases my code might fail? Or what are the critical test-cases for this problem?

Here’s the link to the problem : KFIB

Here’s my solution for the same : solution

I am getting WA for some test cases.

hi @jjtomar

try this : 200000 2

correct answer is : 216653165

it’s giving incorrect as it overflowing the range!

corrected code : CodeChef: Practical coding for everyone

take modulus when you are finding sum
even then time complexity of your solution can be decreased

1 Like

@vijju123 help!!!

thanks. so can we take modulus everytime when summing? will the answer still be equivalent to taking modulus just once in the last?

no the sum will overflow so you have to take modulus

Yes, the answer will be equivalent