Meta Variants for Merge K Sorted Lists (LC23)
2187

Hey y’all! Hope all is well. I got another solution up, this time for a Top 20 Meta tagged question: Leetcode 23 Merge K Sorted Lists and its 2 variants.

I’ve never seen the original LC problem be asked where you’re given a list of LinkedLists…but maybe once or twice? It’s way more likely that you’ll be asked one of the two variants:
#1 What if you were given a list of integer arrays?
#2 What if you had to merge K sorted lists but as an Iterator class?

The good news is, Leetcode’s somewhat recently updated their editorial to have the Min Heap solution, which is what I went with in the video (but yes, Divide-and-Conquer works too).

As a footnote, there are other variants of these variants too (which I don’t cover):
#1 What if you were given a list of integer arrays, but you had to exclude duplicate integers in the merged result?
#2 What if you were given a list of intervals? Meta…loves their intervals.
I’ll definitely do a follow-up video sometime, but the first 2 listed variants are the most commonly asked ones.

Check it out (or not!):

Leetcode 23 Merge K Sorted Lists

23_Merge_K_Sorted_Lists_Thumbnail.png


Reference to the OG LC problem: https://leetcode.com/problems/merge-k-sorted-lists/description/

Good luck on your phone screens & onsite loops.

Comments (1)