Master Data Structures & Algorithms For FREE at AlgoMap.io!
@chisomedoka56516 ай бұрын
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.
@GregHogg6 ай бұрын
Haha yeah, this is one of my favorite questions because of that!!
@thetruth657562 ай бұрын
huge fan of neetcode but i gotta admit your solution for this problem is much easier to understand lol
@mkhile15896 ай бұрын
Very good explanation.Your shorts video explanations are also so clear.
@GregHogg6 ай бұрын
Thank you glad to hear it!
@Anantlahamge074 күн бұрын
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.
@rajarshibiswas94245 ай бұрын
bro your explanation are really solid 👌 carry one
@GregHogg5 ай бұрын
Thank you!!
@shantipriya3702 ай бұрын
what an amazing explanation..
@SeanKearney-g7d3 ай бұрын
Is the merge sort type solution preferred over the heap solution?
@knighthawk0956 ай бұрын
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*
@igml11455 ай бұрын
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
@gabrielfonseca16423 ай бұрын
The total number of elements is n, so sorting the flattened list is O(nlogn) which is worse than O(nlogk).
@tinutom8106 ай бұрын
1st
@christianjt70185 ай бұрын
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
@GregHogg5 ай бұрын
Simpler maybe, but slower! Then heap pops take log n time instead of log k time