Infosys interview question

data structure and algorithm hard.