I tried the following approach and I see my solution fails the efficiency test.
- Find the breadth of the tree in O(n) time complexity
- Create an array list of lists of size equal to the breadth of the tree.
- Traverse the tree and add nodes to the list corresponding to the vertical. Again O(n) time complexity.
Not sure why O(nlogn) solution gets through and not O(n).