[Amazon phone screen] Rebuild binary tree given an input matrix of nodes.

Given an input like:

[2, 4]
[1, 2]
[3, 6]
[1, 3]
[2, 5]

Use it to reconstruct this binary tree:

             1
          2      3
       4   5  6

Note that:
a) The first number in each line is a parent.
b) Second number is a child.
c) The left child always shows up in the input before the right child.

Return root.

I was given about 20 minutes to solve this and couldn't do it.

Comments (5)