Kth Smallest Number in M Sorted Lists
Try to solve the Kth Smallest Number in M Sorted Lists problem.
We'll cover the following
Statement#
Given an number of sorted lists in ascending order and an integer, k, find the smallest number among all the given lists.
Although there can be repeating values in the lists, each element is considered unique and, therefore, contributes to calculating the smallest element.
If k is greater than the total number of elements in the input lists, return the greatest element from all the lists, and if there are no elements in the input lists, return 0.
Constraints:
-
m -
list[i].length -
list[i][j] -
k
Examples#
1 of 3
2 of 3
3 of 3
Understand the problem#
Let’s take a moment to make sure you’ve correctly understood the problem. The quiz below helps you check if you’re solving the correct problem:
Smallest Number in Sorted Lists
What is the output if the following lists and the value of k are given as input?
list = [1, 4, 5]
list = [4, 7, 8]
list = [2, 6, 9]
k = 5
7
5
6
Figure it out!#
We have a game for you to play. Rearrange the logical building blocks to develop a clearer understanding of how to solve this problem.
Try it yourself#
Implement your solution in main.py in the following coding playground.
Solution: Merge Sorted Array
Solution: Kth Smallest Number in M Sorted Lists