Databricks Interview Question

Three dynamic programming and backtracing problem