Leetcode Problem 1851. Minimum Interval to Include Each Query
1851. Minimum Interval to Include Each Query
Leetcode Solutions
Priority Queue Approach
Sort the intervals by their starting points.
Sort the queries and maintain their original indices for the result array.
Initialize a priority queue (min-heap) to store intervals, ordered by interval size and then by ending point.
Iterate through the sorted queries:
a. Add all intervals to the priority queue that start before or at the current query point.
b. Remove intervals from the priority queue that end before the current query point.
c. If the priority queue is not empty, the top element's size is the answer for the current query; otherwise, the answer is -1.
Store the answers in the result array using the original indices of the queries.