Domanda di colloquio di Amazon

graphs question.time complexity of the approach,optimal solution