Infosys Interview Question

Graph problem