Infosys interview question

Graph problem