O(n) solution failing efficiency test


I tried the following approach and I see my solution fails the efficiency test.

  1. Find the breadth of the tree in O(n) time complexity
  2. Create an array list of lists of size equal to the breadth of the tree.
  3. 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).


hey ! mine too. i think it is an issue of programming language. in my solution i iterate over A once too.