Sometimes Wish I Was a House Cat

If I was not a human, I know with certainty, I would want to be a house cat. I've learned some ways from my cat how to live as comfortably as he does.

Smartphone

独家优惠奖金 100% 高达 1 BTC + 180 免费旋转




406. Queue Reconstruction by Height

Sort by height in descending order, then by k in ascending order. Thus, when traversing the list, we start seeing taller people, people with the same height but lower order of precedence.

For example, given [[7,0], [4,4], [7,1], [5,0], [6,1], [5,2]]. After being sorted, it becomes [[7,0], [7,1], [6,1], [5,0], [5,2], [4,4]]. Then we start the insertion.

Insert [7,0]: [7,0]
Insert [7,1]: [7,0], [7,1]
Insert [6,1]: [7,0], [6,1], [7,1]
Insert [5,0]: [5,0], [7,0], [6,1], [7,1]
Insert [5,2]: [5,0], [7,0], [5,2], [6,1], [7,1]
Insert [5,2]: [5,0], [7,0], [5,2], [6,1], [4,4], [7,1]

Time: O(NlogN) Space: O(N)

Add a comment

Related posts:

WHO IS THERAPY FOR?

Everyone. Everyone can benefit from therapy. More specifically, anyone who wants to improve in any area of life can benefit from therapy. You want to make sure it’s the right kind of therapy for your…

You Live a Life of Contradictions

I loved when I should have run away I cried when I should have been the one that was strong I was harsh when kindness was needed I was too timid when I should have stood my ground Contradictions are…

Linear Regression

Before we move onto linear regression, we need to get the basic understanding of the word ‘regression’, rather ‘regression analysis’. Regression analysis is one of the most common methods of…