We need to enumerate all paths and then keep track of the smallest path sum.
Again, let’s use reduction
to reduce this problem into smaller problems. To comupte the minimum path sum from (0,0)
to (m,n)
, we would first need to know the minimum path sum till (m-1, n)
and (m, n-1)
.
Once we have reduced our problem, we can put into a recursive statement and we are done.
Code
Python3
Big O Analysis
-
Runtime
The runtime complexity here is since are caching - which reduces the to linear time.
-
Memory
The memory usage is since we are caching.
— A