1851. Minimum Interval to Include Each Query

Practice Minimum Interval to Include Each Query for free on NudgeCode: Hard, Greedy pattern. Write it in Python or JavaScript, run the tests in your browser, and ask for a hint when you are stuck.

Each [left, right] in intervals covers the integers from left to right, so its size is right - left + 1. For every value q in queries, find the smallest size of an interval that contains q, or -1 if none does. Return the answers in the same order as queries.

Example

intervals = [[1,4],[2,4],[3,6],[4,4]], queries = [2,3,4,5]  ->  [3,3,1,4]

Constraints