Minimum Interval to Include Each Query
For each query value q, return the length end-start+1 of the smallest closed interval containing q, or -1 if none contains it. Preserve query order.
Example 1
intervals = [[1,4],[2,3],[6,8]]
queries = [3,5,7,3][2,-1,3,2]Explanation
3 uses [2,3] of length 2, 5 has no match, and 7 uses [6,8] of length 3; repeated 3 repeats its answer.
Example 2
intervals = [[4,4]]
queries = [4,3][1,-1]Explanation
The singleton closed interval contains 4 with length one but excludes 3.
Example 3
intervals = [[1,10],[2,5]]
queries = [1,5,10][10,4,10]Explanation
Only [1,10] covers 1 and 10; 5 uses shorter [2,5] of inclusive length 4.
Constraints
- 1 <= number of intervals,queries <= 100000
- Interval and query values are positive <= 10000000
- Every interval has start <= end
Function contract
minIntervalArguments: json, jsonSolutionRuns on your device
Loading draft…
Run: 3 examples; Submit: 35 cases, on your device.
[[1,4],[2,3],[6,8]][3,5,7,3]