Round 1
Questions: Problem 1: An Amazon based auto-delivery van is traversing through hills and the path of the road is in a peculiar way. Descending from the top of the hill, the road moves from right to left before reaching a hairpin bend and switching from left to right. This process continues till the end of the hill.
Boiling it down, it's basically the zigzag traversal problem.
Example 1: Input:
1 / \ 2 3 / \ / \ 4 5 6 7
Output: 1 3 2 4 5 6 7
Example 2: Input:
1 / \ 2 3 / / 4 6
Output: 1 3 2 4 6
Constraints: No constraints specified.
Candidate's Approach
Used a queue to enqueue all children nodes of the current level. Kept track of the current level as well as the size of each level to reverse the order whenever the level was even (root at level 1).
Extension: Reduce space complexity by not keeping a list of nodes in the current level. Utilised a double ended queue to poll from the end at even levels.
Interviewer's Feedback
No feedback provided.