Queue Reconstruction by Height | queue reconstruction by height leetcode python | leetcode 406

preview_player
Показать описание
Please like the video, this really motivates us to make more such videos and helps us to grow. thecodingworld is a community which is formed to help fellow student and professionals looking to crack the “coding interviews”.

We love solving and sharing problems which are frequently asked in technical interviews and voted by community at various websites.

✅ For more and upcoming updates join our community

#leetcode #python
Рекомендации по теме
Комментарии
Автор

I would recommend you talk about the use of `key = lambda p : (-x[0], x[1])` that is the one thing people may easily forget because this is the way to make sure the order of the same value to be in right place. It is the minus sign to make the sort to be in reverse order but it also makes sure the same value x[0 will be in normal sort order the incremental order.

myronyoo
Автор

Thanks man for sharing intuition behind this
Every one explains 🙄 code but your video gave how and why we r doing this

editorera
Автор

thanks. i got it when you pointed out that the smaller items don't care about the larger items. didn't have to look at the code this time.

dmh
Автор

hey thanks very much for your simple and yet effective solution explanation. Just one kind request, if possible please do mention time and space complexity as well. appreciate your help and happy coding!

ronakagrawal
Автор

I really liked the 5 min meditation in your description

neilpradhan
Автор

Thank you! your videos are very concise, at the same time I never feel lost while listening to your explanations

RheaAnand
Автор

class Solution(object):
def reconstructQueue(self, people):
"""
:type people: List[List[int]]
:rtype: List[List[int]]
"""
pass1 = sorted(people, key=lambda x: (x[0], -x[1]), reverse=True)
pass2 = []
for x in pass1:
pass2.insert(x[1], x)
return pass2


just do this.
Sort with key=h-k in descending order and store in pass1.
then insert each person in a new list at the position k. This should be done in order of pass1

architagupta
Автор

But generally your video is so good and I like it very much!

myronyoo
Автор

what is p[1]? is is the key? shouldnt it be p[0] for the height? since the lists are like [h, k] not [k, h]

cocoarecords
Автор

people = sorted(people, lambda x: (-x[0], x[1])) can someone explain this briefly
Thanks in Advance

geekydanish