Infosys interview question

A DP coding question on their website