Infosys interview question

Sorting