Tap here to switch tabs
Problem
Submissions

Problem: Minimum Absolute Difference Queries

med
30 min
Try to solve the Minimum Absolute Difference Queries problem.

Statement

You are given an integer array nums and a 2extD2 ext{D} integer array queries, where each queries[i] is of the form [li,ri][l_i, r_i].

For each query, consider the subarray nums[li…ril_i \dots r_i]. The minimum absolute difference of this subarray is defined as the minimum absolute difference between any two elements in the subarray that have different values. If all elements in the subarray are identical, the minimum absolute difference is defined as −1-1.

Return an array containing the answers to all queries in the given order.

Constraints:

  • 2≤2 \leq nums.length ≤105\leq 10^5

  • 1≤1 \leq nums[i] ≤100\leq 100

  • 1≤1 \leq queries.length ≤2imes104\leq 2 imes 10^4

  • 0≤li<ri<0 \leq l_i < r_i < nums.length

⋮
Tap here to switch tabs
Problem
Submissions

Problem: Minimum Absolute Difference Queries

med
30 min
Try to solve the Minimum Absolute Difference Queries problem.

Statement

You are given an integer array nums and a 2extD2 ext{D} integer array queries, where each queries[i] is of the form [li,ri][l_i, r_i].

For each query, consider the subarray nums[li…ril_i \dots r_i]. The minimum absolute difference of this subarray is defined as the minimum absolute difference between any two elements in the subarray that have different values. If all elements in the subarray are identical, the minimum absolute difference is defined as −1-1.

Return an array containing the answers to all queries in the given order.

Constraints:

  • 2≤2 \leq nums.length ≤105\leq 10^5

  • 1≤1 \leq nums[i] ≤100\leq 100

  • 1≤1 \leq queries.length ≤2imes104\leq 2 imes 10^4

  • 0≤li<ri<0 \leq l_i < r_i < nums.length