This question applies to both leetcode and real life interviews.
Say we are trying to solve N fibonacci. The starting code will usually be given to us like this:
def getNthFib(n):
#Write your code here If we decide to use the memoization method, where the memo has to get passed into a recursive function, are we allowed to change the original function to this?:
def getNthFib(n, memo={1:0, 2:1}):
#Write your code here Or are you supposed to have the original function call another function? Like this:
def getNthFib(n):
memo = {1:0, 2:1}
self.recurseFib(n, memo)
def recurseFib(self, n, memo):
#Write your code here I always see people changing the function signature parameters in the discussions for questions. Is this something that you should avoid doing?