Solution: Kth Smallest Number in M Sorted Lists
Let's solve the Kth Smallest Number in M Sorted Lists problem using the K-Way Merge pattern.
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