It is a very basic question. Given a m*n matrix, start from (0,0) and end at (m-1, n-1).
Output all the possible path using backtrack.
I came up with a solution in 10 minites, something like:
def allPath(m,n):
def backtrack(i, j, temp_res):
if i == m-1 and j == n-1:
# print(temp_res)
res.append(temp_res)
return
if i > m-1 or j > n-1:
return
temp_res.append([i,j])
backtrack(i+1, j ,temp_res)
backtrack(i, j+1, temp_res)
temp_res.pop()
res = []
backtrack(0,0,[])
return resThis code return with right size of the answer. For example, m=3,n=7, answer is sized 28. But the lists are all empty inside the res. But when I print (in the place I commented in the code), the print output looks fine.
Any idea what I missed?
UPDATE:
the second question I got for this round:
change a BST to a doubly linked list. I think there is a same question in LC.
UPDATE2:
Recieved the onsite schedule email.