DoorDash interview question

First one based on tree, Second on based on BFS