Hi I was wondering why can't we use recursive Solution for Coin Piles Solution. This is the Problem
I have tried recursive solution but end up getting TLE and Runtime Error. Can anyone explain whether we can use Recursion or Dynamic Programing. This is my Solution.
See the constraint on a, b (1e9). It seems yours code taking O(ab) time and memory
Yeahh. Ok got it. But the recurrence was correct?
apart from (time / space complexity) yours recurrence solution was correct, but generally recursive solution was slower than dp.
You also can solve it as O(1)