My top-down approach(recursion) gives stack overflow error under efficiency.....but my bottom-up approach(iteration) solution is getting accepted, why?


#1

Comment body goes here.


#2

The depth of the recursive calls is causing the issue here and since we cannot use some optimization like tail call optimization so under the constraints set in the judge, it seems you need to use the iterative approach