Uber Interview Question

Tree based question, traversal using DFS/BFS