title: 406(LeetCode). Queue Reconstruction by Height
body: <p><strong>So here is the question:</strong></p>
  
  <p><a href="https://leetcode.com/problems/queue-reconstruction-by-height/" rel="nofollow noreferrer">https://leetcode.com/problems/queue-reconstruction-by-height/</a></p>
  
  <p>Suppose you have a random list of people standing in a queue. Each person is described by a pair of integers (h, k), where h is the height of the person and k is the number of people in front of this person who have a height greater than or equal to h. Write an algorithm to reconstruct the queue.</p>
  
  <p>Note:
  The number of people is less than 1,100.</p>
  
  <p>Example:</p>
  
  <pre><code>Input:
  [[7,0], [4,4], [7,1], [5,0], [6,1], [5,2]]
  
  Output:
  [[5,0], [7,0], [5,2], [6,1], [4,4], [7,1]]
  </code></pre>
  
  <p>And here is my answer using javascript:</p>
  
  <pre><code>var reconstructQueue = function(people) {
  var result= [];
  people.sort((a,b)=&gt;a[1]-b[1]).sort((a,b)=&gt;b[0]-a[0]);
  for(var i=0; i&lt;people.length; i++) {
      result.splice(people[i][1], 0, people[i]);
  }
  return result;
  };
  </code></pre>
  
  <p>It can pass the test above, but Why didn't it pass all the tests in Leetcode? Can anybody help me?</p>