I am trying to solve the following problem using Python 3: https://www.hackerrank.com/contests/projecteuler/challenges/euler015.
Following is my code:
def dp(x,y):
global MEMO,N,M
if x>N or y>M:return 0
if x==N and y==M:
return 1
if MEMO[x][y]!=-1:return MEMO[x][y]
MEMO[x][y]=(dp(x+1,y)+dp(x,y+1))%1000000007
return MEMO[x][y]
MEMO=[[-1]]
N=0
M=0
tc=int(input())
while tc:
tc-=1
N,M=map(int,input().split())
MEMO=[[-1]*(M+1)]*(N+1)
print(dp(0,0))
However, for the given test case, it gives answer 3(not 6). I think it has something to do with the local/global scoping of variables. Where am I going wrong?