Uber interview question

Tree based question, traversal using DFS/BFS