Challenges • Asked almost 5 years ago by Anonymous
The two examples present in the question contradict each other.
For the first tree,
1
/ \
2 3
/ \
4 5
The traversal presented is is left to right on second level and right to left on third level, giving us [[1], [2, 3], [5, 4]
But for the second tree
4
/ \
3 12
/ \
8 14
The traversal presented is is right to left on second level and left to right on third level, giving us [[4], [12, 3], [8, 14]
So the traversal logic is different in both examples, and that's reflected even with the test cases present, especially the last one
tree5 which adheres to the first tree logic
Link to problem: Traverse In A Zig Zag.
Thanks for catching this! We've updated the problem and ensured that all test cases pass.