title: How to use balanced binary trees to solve this challenge?
body: <pre><code>       1(70)
          / \
         /   \
      2(40)  5(10)
       / \      \
      /   \      \
   3(60)  4(80)  6(20)
           / \
          /   \
       7(30)  8(50)
  </code></pre>
  
  <p>This is for an online challenge (not live contest). I don't need someone to solve for me, just to push in right direction. Trying to learn.</p>
  
  <p>Each node has a unique ID, no two people have same salary. Person #1 has salary $70, person #7 has $30 salary, for example. Tree structure denotes who supervises who. Question is who has kth lowest salary on a person's subordinates.</p>
  
  <p>For example I choose person #2. Who is 2nd lowest among subordinates? #2's subordinates are 3, 4, 7, 8. 2nd lowest salary is $50 belonging to person #8.</p>
  
  <p>There are many queries so structure to must be efficient.</p>
  
  <p>I thought about this problem and researched data structures. Binary tree seems like a good idea but I need help.</p>
  
  <p>For example I think ideal structure look like, for person #2:</p>
  
  <pre><code>    2(40)  
       / \      
      /   \      
   7(30)  3(60)
           / \
          /   \
       8(50)  4(80)
  </code></pre>
  
  <p>Every child node is subordinate of #2, every left branch has lower salary than on right. If I store how many children at each node I can get kth lowest.</p>
  
  <p>For example: From #2, left branch 1 node, right branch 3 nodes. So 2nd lowest - 1 means I now want 1st lowest in right branch.</p>
  
  <p>Move to #3, 1st lowest points to #8 with $50 which is correct.</p>
  
  <p>My question:</p>
  
  <ol>
  <li><p>Is this approach as I describe it a good one? Is it a valid approach?</p></li>
  <li><p>I am having trouble figuring out how to construct this kind of tree. I think I can make them recursively. But hard to figure out how to make all children into new tree sorted by salary. Need some light help.</p></li>
  </ol>