Find the Narrowest Interval Meeting Every Sorted List

Quick Overview

Find the Narrowest Interval Meeting Every Sorted List. Return [a,b] containing at least one element from every sorted list in nums.

Find the Narrowest Interval Meeting Every Sorted List

Company: Amazon

Role: Software Engineer

Category: Coding & Algorithms

Difficulty: hard

Interview Round: Other

### Problem Return [a,b] containing at least one element from every sorted list in nums. Minimize b-a, breaking equal-width ties by the smaller a. Endpoints are inclusive. ```cpp class Solution { public: vector<int> smallestRange(vector<vector<int>>& nums); }; ``` ### Examples **Example 1:** ```text nums = [[1,6],[3,8],[4,7]] Output: [6,8] Explanation: 6,8,7 cover all lists in width two. ``` **Example 2:** ```text nums = [[0,5],[1,6]] Output: [0,1] Explanation: [5,6] has equal width but a larger left endpoint. ``` ### Constraints - There are k=nums.length lists, with k in 1..3500. Each has 1..50 entries in nondecreasing order. Values range from -100000 through 100000. ### Clarifying Questions Cover every list, keep the running maximum synchronized and apply the explicit left-endpoint tie-break. ```hint Read the boundary condition Which current list value must change before an interval can become narrower? ``` ### Contract considerations Cover every list, keep the running maximum synchronized and apply the explicit left-endpoint tie-break.

Overview: Find the Narrowest Interval Meeting Every Sorted List. Return [a,b] containing at least one element from every sorted list in nums.

Amazon logo
Amazon
Source window: 0–3 months · as of Oct 21, 2026
hardSoftware EngineerOtherCoding & Algorithms
0
0

Problem

Return [a,b] containing at least one element from every sorted list in nums. Minimize b-a, breaking equal-width ties by the smaller a. Endpoints are inclusive.

class Solution {
public:
    vector<int> smallestRange(vector<vector<int>>& nums);
};

Examples

Example 1:

nums = [[1,6],[3,8],[4,7]]
Output: [6,8]
Explanation: 6,8,7 cover all lists in width two.

Example 2:

nums = [[0,5],[1,6]]
Output: [0,1]
Explanation: [5,6] has equal width but a larger left endpoint.

Constraints

  • There are k=nums.length lists, with k in 1..3500. Each has 1..50 entries in nondecreasing order. Values range from -100000 through 100000.

Clarifying Questions Guidance

Cover every list, keep the running maximum synchronized and apply the explicit left-endpoint tie-break.

Contract considerations

Cover every list, keep the running maximum synchronized and apply the explicit left-endpoint tie-break.