• + 40 comments

    Maybe it needs to add detail about tree representation, i.e. that at any level left subtree never can overlap right subtree and vice versa. In the beginning I was confused - what is expected in following cases:

          1
         / \
        2   3
       / \
      4   5
           \
            6
             \
              7
    

    Expected: 4-2-1-3-7 ? In fact - 4-2-1-3.

          1
         / \
        2   3
       / \
      4   5
         / 
        6
       /
      7
     /
    8 
    

    Expected: 8-4-2-1-3 ? In fact - 4-2-1-3, again.