Amazon interview question

Medium Level Leetcode problem: BFS on tree