DIY: Merge K Sorted Lists

Solve the interview question "Merge K Sorted Lists" yourself in this lesson.

We'll cover the following

Problem statement

Now, you will be given multiple sorted arrays and your task is to merge them into a single sorted array.

Input

The input will be an array of multiple sorted array. 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 array. 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 array of multiple sorted arrays. This function will return a single array of sorted numbers.

Level up your interview prep. Join Educative to access 80+ hands-on prep courses.