Grokking 75: Top Coding Interview Questions
Ask Author
Back to course home

0% completed

Vote For New Content
Smallest Range Covering Elements from K Lists (hard)
Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Problem Statement

You are given k lists of sorted integers. Each list is in non-decreasing order.

Find the smallest range that includes at least one number from each of these k lists. The range [a, b] is smaller than range [c, d] if b - a < d - c or a < c if b - a == d - c.

Examples

Example 1:

  • Input: nums = [[1, 5, 8], [4, 12], [7, 8, 10]]
  • Expected Output: [4, 7]
  • Justification: The range [4, 7] includes 5, 4, and 7 numbers from the first, second and third list respectively.

Example 2:

  • Input: nums = [[3, 6, 7], [2, 4, 8], [1, 9, 10]]
  • Expected Output: [1, 3]
  • Justification: The range [1, 3] includes 3, 2, and 1 numbers from the first, second and third list respectively.

Example 3:

  • Input: nums = [[10, 15, 24], [20, 25, 30], [12, 18, 22]]
  • Expected Output: [22, 25]
  • Justification: The range [22, 25] includes 24, 25, and 22 numbers from the first, second and third list respectively.

Constraints:

  • nums.length == k
  • 1 <= k <= 3500
  • 1 <= nums[i].length <= 50
  • -10<sup>5</sup> <= nums[i][j] <= 10<sup>5</sup>
  • nums[i] is sorted in non-decreasing order.

Try it yourself

Try solving this question here:

Python3
Python3

. . . .

.....

.....

.....

Like the course? Get enrolled and start learning!

Table of Contents

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible

Contents are not accessible