`
class Solution:
def path(self, m: int, n: int, dp: dict = {}) -> int:
if m == 1 or n == 1:
return 1
key = f"{m}:{n}"
if key not in dp.keys():
dp[key] = self.path(m - 1, n) + self.path(m, n - 1)
return dp[key]
def uniquePaths(self, m: int, n: int) -> int:
return self.path(m, n)
`
This is my code, my doubt is, I am not passing dp variable in the recursion call still dp storing values.
By mistake, I forget to pass dp as an argument, and when I realized I pass the variable and the behavior of the code is identical.
I don't understand how dp variable is able to store the values when it is not being passed in the recursion call?
I was expecting the code will work like normal recursion code, but not as a Dynamic Problem, but it is working as a Dynamic Problem, How?