Domanda di colloquio di Apple

Graph traversal question with optimization follow up