Kth Smallest Number in M Sorted Lists

Try to solve the Kth Smallest Number in M Sorted Lists problem.

Statement

Given an mm number of sorted lists in ascending order and an integer, k, find the kthk^{th} 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 kthk^{th} 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:

  • 1≤1\leq m ≤50\leq50
  • 0≤0\leq list[i].length ≤50\leq 50
  • −109≤-10^9\leq list[i][j] ≤109\leq 10^9
  • 1≤1\leq k ≤109\leq 10^9

Examples

Create a free account to view this lesson.

Continue your learning journey with a 14-day free trial.

By signing up, you agree to Educative's Terms of Service and Privacy Policy