Infosys Interview Question

Coding question on heap and graph.