- the problem lies with it being an n-ary tree which makes the traversal order a little more complicated
- binary tree traversal: left->right->current node
- n-ary tree traversal: each child from left to right-> current node
π€What Did I Struggle With?
~
π‘ Explanation of Solution
- recursive solution
- init an empty result vector
- for each child in the roots children
- construct a new vector that is the result of recursive call with the child as the param
- insert that childResult into our result vector
- push the value of the current node into the result vector
- return the result
β Complexity Analysis
Time Complexity: O(n) where N nodes are traversed once
Space Complexity: O(n) due to the recursion call stack