Answer: Asana SWE Interview Question 2024 June | Trees and BFS | on-campus

Answer · Posted Jun 2026

Solution: BFS with Level-Size Tracking Approach Use a queue to perform BFS. The key insight for grouping nodes by level is to capture the queue size at the start of each iteration — this tells you exactly how many nodes belong to the current level. Process exactly that many nodes, adding each node's value to the current level list and enqueueing its children. After processing all nodes at the current level, add the level list to the result and move ...

The full answer & interview discussion are available to premium members.

Log in Create a free account