Smallest Range Covering Elements from K Lists
Updated
Problem statement
You are given k nonempty lists of integers, each sorted in nondecreasing order.
Return the inclusive range [left, right] with the smallest width that contains at least one value from every list. If several ranges have the same width, return the one with the smaller left endpoint.
Function
smallestRange(nums: List<List<Integer>>) → int[]Examples
Example 1
nums = [[4,10,15,24,26],[0,9,12,20],[5,18,22,30]]return = [20,24]The interval contains 24, 20, and 22, one value from each list, and no narrower interval covers all three lists.
Example 2
nums = [[1,2,3],[1,2,3],[1,2,3]]return = [1,1]The single value 1 appears in every list.
Constraints
1 <= nums.length <= 3500.- Each list contains from
1through50values. - The total number of values is at most
10^5. -10^5 <= nums[i][j] <= 10^5.- Every list is sorted in nondecreasing order.
More Snap Inc. interview questions
- ID Allocator with Assign and ReleasePHONE SCREEN · Seen Nov 2026
- Basic Calculator IIPHONE SCREEN · Seen Oct 2026
- Stream Cluster Max and MedianPHONE SCREEN · Seen Oct 2026
- LRU Cache with Thread-Safety Follow-UpPHONE SCREEN · Seen Sep 2026
- Most Stones Removed with Same Row or ColumnPHONE SCREEN · Seen Sep 2026
- Report Island Areas in Discovery OrderPHONE SCREEN · Seen Aug 2026
- Render an Org Chart and Find Skip-Level PairsONSITE INTERVIEW · Seen Nov 2026
- Peak of an Increasing-Then-Decreasing ArrayONSITE INTERVIEW · Seen Oct 2026
- Number of Closed IslandsONSITE INTERVIEW · Seen Oct 2026
- Radar Barrier CrossingONSITE INTERVIEW · Seen Oct 2026
Similar questions at other companies
- Detect Security Attacks from Network LogsFireworks AI · PHONE SCREEN
- Top K Frequent ElementsAmazon · OA · PHONE SCREEN · ONSITE INTERVIEW
- Mutual-Friend RecommendationsMeta · PHONE SCREEN · ONSITE INTERVIEWMeta interview questions
- Top K Frequent ElementsGoogle · PHONE SCREENGoogle interview questions
- Top K Frequent ElementsApple · PHONE SCREENApple interview questions
- Top K Frequent ElementsC3.ai · PHONE SCREENC3.ai interview questions
- Sliding Window MedianNotion · ONSITE INTERVIEWNotion interview questions
- Sliding Window MedianBloomberg LP · ONSITE INTERVIEWBloomberg LP interview questions
- Choose One from Each Set to Minimize the RangeInMobi · OAInMobi interview questions
- API Rate Limit Violation DetectionTekion · OATekion interview questions