Getting tle in few test cases

i am following recursion but getting tle on few cases is the logic wrong or am i supposed to follow dp?

yes, dp!!
as many of your fellows have same problem!!
do it after dp

also,
you should take modulo within the recursion i.e.
β€˜return (horizontal + vertical)%1000000007;’

hi @pradyumn25jain yes you need to use memoization here to reduce the time complexity

alright thank you so much

1 Like