DoorDash Interview Question

First one based on tree, Second on based on BFS