Minimum Interval to Include Each Query
Solve this the way you would in the interview: out loud, on a timer, with an AI interviewer asking follow-ups while you code. You get a scored report at the end.
Practice this as a mock interviewFree to start, no account neededProblem
You are given a list of closed integer intervals, where intervals[i] = [left_i, right_i] covers every integer from left_i to right_i inclusive. Its **size** is right_i - left_i + 1.
You are also given an array queries. For each queries[j], find the **smallest size** of any interval that contains queries[j] (i.e. left_i <= queries[j] <= right_i). If no interval contains it, the answer is -1.
Return an array answer where answer[j] is the result for queries[j], in the original query order.
Examples
Constraints
- `1 <= intervals.length, queries.length <= 10^5`
- `1 <= left_i <= right_i <= 10^7`
- `1 <= queries[j] <= 10^7`
What the interviewer grades
A correct solution is one of five scores. The report also grades problem understanding (did you clarify inputs and edge cases before coding), problem solving, communication while you work, code quality, and testing. See a sample report, or read up on the pattern in the lessons.