Code
Python3
Big O Analysis
-
Runtime
The runtime complexity here is after memoizing. Before memoizing it’s since there are two functions calls for every call. After memoizing, since we store a pair
(i, j)
. -
Memory
The memory usage is since we use the
collections.defaultdict
object to store memoized results.
— A