Imagine you're analyzing data patterns across different segments of a dataset. You need to find the minimum absolute difference between any two distinct values within specific ranges.
The minimum absolute difference of an array is the smallest value of |a[i] - a[j]| where 0 <= i < j < a.length and a[i] != a[j]. If all elements are identical, return -1.
Example: For array [5, 2, 3, 7, 2], the minimum absolute difference is |2 - 3| = 1. Note that we can't use |2 - 2| = 0 because the elements must be different values.
Given an integer array nums and multiple queries where queries[i] = [li, ri], you need to compute the minimum absolute difference for each subarray nums[li...ri] (inclusive).
Goal: Return an array where each element is the answer to the corresponding query.
Input & Output
Constraints
- 2 ⤠nums.length ⤠105
- 1 ⤠nums[i] ⤠100
- 1 ⤠queries.length ⤠2 à 104
- 0 ⤠li < ri < nums.length
- Key constraint: Values bounded to 1-100 enables frequency counting optimization