Merge K Sorted Linked Lists - Leetcode 23 - Heaps (Python)

  Рет қаралды 6,264

Greg Hogg

Greg Hogg

Күн бұрын

Пікірлер: 18
@GregHogg
@GregHogg 5 ай бұрын
Master Data Structures & Algorithms For FREE at AlgoMap.io!
@chisomedoka5651
@chisomedoka5651 6 ай бұрын
The “Haha” moment that came after you mentioned heap. Your explanations are so clear, I love how you breakdown the problem and solution just before coding it out, I just might stand a chance with interviewing.
@GregHogg
@GregHogg 6 ай бұрын
Haha yeah, this is one of my favorite questions because of that!!
@thetruth65756
@thetruth65756 2 ай бұрын
huge fan of neetcode but i gotta admit your solution for this problem is much easier to understand lol
@mkhile1589
@mkhile1589 6 ай бұрын
Very good explanation.Your shorts video explanations are also so clear.
@GregHogg
@GregHogg 6 ай бұрын
Thank you glad to hear it!
@Anantlahamge07
@Anantlahamge07 4 күн бұрын
Hey Greg, you said we need to add the values to the heap but in the code you added tuples in the heap. Why is that so? That's the only part I am confused about.
@rajarshibiswas9424
@rajarshibiswas9424 5 ай бұрын
bro your explanation are really solid 👌 carry one
@GregHogg
@GregHogg 5 ай бұрын
Thank you!!
@shantipriya370
@shantipriya370 2 ай бұрын
what an amazing explanation..
@SeanKearney-g7d
@SeanKearney-g7d 3 ай бұрын
Is the merge sort type solution preferred over the heap solution?
@knighthawk095
@knighthawk095 6 ай бұрын
How is this approach different from, flattening the input into a single list, sorting the list and then creating the linked list? *Food for thought*
@igml1145
@igml1145 5 ай бұрын
It is more efficient to do the heap solution. Flattening the input will “lose” the information that the inner linked lists are sorted depending on the sorting algorithm that you use, as it might start making comparisons between elements of the same inner linked list
@gabrielfonseca1642
@gabrielfonseca1642 3 ай бұрын
The total number of elements is n, so sorting the flattened list is O(nlogn) which is worse than O(nlogk).
@tinutom810
@tinutom810 6 ай бұрын
1st
@christianjt7018
@christianjt7018 5 ай бұрын
I think the code is simpler if we just put all the nodes in the heap and then we start popping all the nodes from the heap. nodes = [] for l in lists: while l: heapq.heappush(nodes,(l.val,l)) l=l.next
@GregHogg
@GregHogg 5 ай бұрын
Simpler maybe, but slower! Then heap pops take log n time instead of log k time
@christianjt7018
@christianjt7018 5 ай бұрын
@@GregHogg oh I see, thanks for the feedback
L25. Merge K Sorted Lists | Multiple Approaches
30:02
take U forward
Рет қаралды 57 М.
K Closest Points to Origin - Leetcode 973 - Heaps (Python)
9:47
Мен атып көрмегенмін ! | Qalam | 5 серия
25:41
黑天使只对C罗有感觉#short #angel #clown
00:39
Super Beauty team
Рет қаралды 36 МЛН
Merge Two Sorted Lists - Leetcode 21 - Linked Lists (Python)
9:41
Merge K Sorted Lists - Leetcode 23 - Python
10:34
NeetCode
Рет қаралды 215 М.
Top K Frequent Elements - Leetcode 347 - Heaps (Python)
14:08
Greg Hogg
Рет қаралды 13 М.
How I would learn Leetcode if I could start over
18:03
NeetCodeIO
Рет қаралды 769 М.
MERGE K SORTED LISTS | LEETCODE 23 | PYTHON OPTIMAL SOLUTIO
19:33
Cracking FAANG
Рет қаралды 3,9 М.
Kth Largest Element in an Array - Leetcode 215 - Heaps (Python)
11:52
How I Mastered Data Structures and Algorithms in 8 Weeks
15:46
Aman Manazir
Рет қаралды 154 М.
8 Data Structures Every Programmer Should Know
17:09
ForrestKnight
Рет қаралды 234 М.
Мен атып көрмегенмін ! | Qalam | 5 серия
25:41