The "Minimum Interval to Include Each Query" is a challenging "Hard" difficulty problem involving ranges and queries. You are given a set of intervals [start, end] and a set of queries (points). For each query, you need to find the size of the smallest interval that contains that point. The size of an interval [start, end] is calculated as end - start + 1. If no interval contains the point, return -1.
This problem is about efficient searching. Since there can be many intervals and many queries, a naive approach where you check every interval for every query will be far too slow.
Companies like Google and Bloomberg ask this to test advanced data structure knowledge. It requires combining Sorting, Priority Queues, and the Offline Query technique.
Key evaluation points:
The Offline Query + Min-Heap pattern is the most effective:
[size, end_time].Intervals: [[1, 4], [2, 3], [3, 6]], Queries: [2, 5]
Sorted Intervals: [[1, 4], [2, 3], [3, 6]]
2:
[1, 4] (size 4), [2, 3] (size 2).[[2, 3], [4, 4]].[2, 3]. It ends at 3, which is . Valid!5:
[3, 6] (size 4).[[2, 3], [4, 4], [4, 6]].[2, 3] ends at 3 (invalid for point 5). [1, 4] ends at 4 (invalid for point 5).[3, 6] (size 4). It ends at 6, which is . Valid!end - start instead of end - start + 1.Learn the "Offline Query" technique. When you have multiple queries and the "state" of the system changes linearly (like points moving along a timeline), sorting the queries allows you to process the entire set in one sweep.
| Title | Difficulty | Topics | LeetCode |
|---|---|---|---|
| Employee Free Time | Hard | Solve | |
| K-th Smallest Prime Fraction | Medium | Solve | |
| Two Best Non-Overlapping Events | Medium | Solve | |
| Kth Smallest Element in a Sorted Matrix | Medium | Solve | |
| Minimum Sum of Squared Difference | Medium | Solve |