why does recursive code fail for some test cases

Revision en1, by anipnwr, 2021-04-29 12:10:12

Hi!

I was trying the at coder dp contest and I wrote a recursive dp solution for problem a . It works fine for 7 test cases but fails for last 4.

The point that is disturbing is that similar logic but iterative code of dp is getting accepted of other people.

Can someone please help me with this or point out my mistake if I am doing a foolish one.

This is my code

This is the iterative code that works

Tags # dp, #recursion,dp

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en7 English anipnwr 2021-04-29 12:24:45 0 (published)
en6 English anipnwr 2021-04-29 12:23:26 2 Tiny change: 'sh one. \nThis is ' -> 'sh one. \n\nThis is '
en5 English anipnwr 2021-04-29 12:23:10 44
en4 English anipnwr 2021-04-29 12:22:25 5
en3 English anipnwr 2021-04-29 12:18:29 351
en2 English anipnwr 2021-04-29 12:12:27 45
en1 English anipnwr 2021-04-29 12:10:12 659 Initial revision (saved to drafts)