DIY: Merge K Sorted Lists
Solve the interview question "Merge K Sorted Lists" in this lesson.
We'll cover the following
Problem statement
You will be given multiple sorted lists and your task is to merge them into a single sorted list.
Input
The input will be a list of multiple sorted lists. The following is an example of input:
{
{2,4,6,8,10}
{1,3,5,7,9}
}
Output
The output should be a single sorted list. For the above input, the output should be:
{1,2,3,4,5,6,7,8,9,10{
Coding exercise
For this coding exercise, you need to implement the function mergeKLists(lists)
, where lists
is the list of multiple sorted lists. This function will return a single list of sorted numbers.
Level up your interview prep. Join Educative to access 80+ hands-on prep courses.