cheetcode

135. Minimum Interval to Include Each QueryHard

For each query, return the size of the smallest interval that contains it.

You are given intervals where intervals[i] = [left, right] and an array of queries.

For each query, return the length of the smallest interval that contains it, or -1 if no interval contains that query.

Examples

Input: intervals = [[1,4],[2,4],[3,6],[4,4]], queries = [2,3,4,5]
Output: [3,3,1,4]
Input: intervals = [[2,3],[2,5],[1,8],[20,25]], queries = [2,19,5,22]
Output: [2,-1,4,6]

Constraints

  • 1 <= intervals.length, queries.length <= 100,000
  • intervals[i].length == 2
  • 1 <= left <= right <= 10,000,000