this is my code
TImelimit for 1 test case
hi @tanjuljain19
Writing a simple recursive solution will time out due to exponential complexity i.e. O (3n ).
Writing a linear dynamic programming solution using arrays will exceed memory limit since N can be 109 in worst case.
To circumvent both of the a aforementioned problem, we can use maps and memoization.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.