Databricks interview question

Three dynamic programming and backtracing problem