Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started

Merge K Sorted Feed Lists

MediumPython00:00
Practice interviewer
In session
5 left
00:00

Your question is Merge K Sorted Feed Lists. Start with the requirements on the right.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.

Problem

In a Meta-style feed aggregation service, multiple independently sorted streams must be combined into one globally sorted result. Given k sorted integer lists, merge them into a single sorted list.

Formal Specification

Implement a function that takes lists, where lists[i] is a sorted list of integers in non-decreasing order, and returns a single list containing all values from every input list in non-decreasing order.

  • Input: lists: List[List[int]]
  • Output: List[int]

Constraints

  • 0 <= k <= 10^4
  • 0 <= len(lists[i]) <= 10^4
  • -10^9 <= lists[i][j] <= 10^9
  • Each list is sorted in non-decreasing order
  • The total number of elements across all lists is at most 10^5

Function Signature

def merge_k_sorted_lists(lists):
Your solutionPython 3
You need to log in / sign up to run or submit.
Run your code to see test output