Addepar Interview Question

Matrix dp question with traversal.