Microsoft interview question

Some DP question related to Matrix path traversal