Hopefully a good explaination


Visualise a 5 x 5 matrix. Starting from 0,0 if you want to find the least path the algorithm would start traversing in both direction the X-axis and Y-axis and will do that recursively at each coordinate.

Now as we are using memset(memoizing) the computation for each coordinate is done only once and saved in memory, any other call requested from another recursion would simply fetch it from memory.

So the computation would just happen 5x5 times.