Problem
You get a list intervals. Each item [left, right] is an interval that includes all the integers from left to right. The size of the interval is right - left + 1.
You also get a list queries of integers. For each query q, find the smallest size of an interval that includes q. An interval includes q when left <= q <= right.
Return a list with one answer for each query, in the same order as queries. If no interval includes a query, the answer for that query is -1.
Example 1
- Input:
- intervals = [[1,5],[3,4],[6,10],[9,9]], queries = [4,7,9,11]
- Output:
- [2,5,1,-1]
- Explanation:
- For the query 4, the interval
[3, 4]has the size 2. For the query 9, the interval[9, 9]has the size 1. No interval includes 11.
Example 2
- Input:
- intervals = [[2,8],[5,6]], queries = [1,5,8]
- Output:
- [-1,2,7]
Constraints
- 1 <= intervals.length <= 10^5
- 1 <= queries.length <= 10^5
- intervals[i].length == 2
- 1 <= left <= right <= 10^7
- 1 <= queries[j] <= 10^7
SysRound wrote this statement. A reference solution checks every example.
Related questions
Continue with questions that share topics or the same question type.
- Calculate Orders Within Each Interval
Coding
- Design stack with O(1) minimum query
Coding · Data Structure Design · Stacks & Queues
- Maximum XOR for Each Query
Coding
- Minimum Number of Operations to Move All Balls to Each Box
Coding
Sources · 1 reference
These records explain where the question appears. A company tag or candidate report does not guarantee a future interview question.
Hello Interview · 1 record
No company association
Leetcode 1851. Minimum Interval to Include Each Query
Reported date not specified · 0 source reports
Source snapshot: Nov 12, 2026
View source