Infosys interview question

Coding question on heap and graph.