Problem
Ask
Submissions

Problem: Minimum Interval to Include Each Query

Medium
30 min
Explore how to determine the smallest interval that includes each query value from a list of intervals. Understand key concepts related to interval sizes and constraints, and apply these to solve interval query problems effectively.

Statement

You are given a 2D integer array, intervals, where each element intervals[i] = [lefti, righti][left_i, \space right_i] represents the ithi^{th} interval on the number line. Each interval includes all integers from leftileft_i to rightiright_i, inclusive. The size (length) of an interval [lefti, righti][left_i, \space right_i] is defined as size=rightilefti+1\text{size} = right_i - left_i + 1.

You are also given an integer array, queries. For each query value queries[j], you must find the smallest-sized interval [lefti, righti][left_i, \space right_i] such that leftiqueries[j]rightileft_i \le queries[j] \le right_i.

  • If at least one interval contains the query, return the minimum interval size among those intervals.

  • If no interval contains the query, return -1 for that query.

Return an array, answer, where answer[j] is the result for queries[j].

Constraints:

  • 11 \leq intervals.length 105\leq 10^5

  • 11 \leq queries.length 105\leq 10^5

  • intervals[i].length ==2== 2

  • 1lefti1 \leq left_i righti\leq right_i 107\leq 10^7

  • 11 \leq queries[j] 107\leq 10^7

Problem
Ask
Submissions

Problem: Minimum Interval to Include Each Query

Medium
30 min
Explore how to determine the smallest interval that includes each query value from a list of intervals. Understand key concepts related to interval sizes and constraints, and apply these to solve interval query problems effectively.

Statement

You are given a 2D integer array, intervals, where each element intervals[i] = [lefti, righti][left_i, \space right_i] represents the ithi^{th} interval on the number line. Each interval includes all integers from leftileft_i to rightiright_i, inclusive. The size (length) of an interval [lefti, righti][left_i, \space right_i] is defined as size=rightilefti+1\text{size} = right_i - left_i + 1.

You are also given an integer array, queries. For each query value queries[j], you must find the smallest-sized interval [lefti, righti][left_i, \space right_i] such that leftiqueries[j]rightileft_i \le queries[j] \le right_i.

  • If at least one interval contains the query, return the minimum interval size among those intervals.

  • If no interval contains the query, return -1 for that query.

Return an array, answer, where answer[j] is the result for queries[j].

Constraints:

  • 11 \leq intervals.length 105\leq 10^5

  • 11 \leq queries.length 105\leq 10^5

  • intervals[i].length ==2== 2

  • 1lefti1 \leq left_i righti\leq right_i 107\leq 10^7

  • 11 \leq queries[j] 107\leq 10^7