Infosys interview question

Based on Dynamic Programming and Graphs mainly.