Infosys interview question

Collections question