Pregunta de entrevista de Uber

Tree based question, traversal using DFS/BFS