Infosys Interview Question

A DP coding question on their website