Do a Depth First Search to get ordered set

     [] 
    / | \
   1  2  3
  /  \
 1,2  1,3
 /
1,2,3
Click here to start solving coding interview questions