Minimum Absolute Difference Queries
The minimum absolute difference of an array a is defined as the minimum value of |a[i] - a[j]|, where 0 <= i < j < a.length and a[i] != a[j]. If all elements of a are the same, the minimum absolute difference is -1.
You are given an integer array nums and the array queries where queries[i] = [li, ri]. For each query i, compute the minimum absolute difference of the subarray nums[li...ri] containing the elements of nums between the 0-based indices li and ri (inclusive).
Return an array ans where ans[i] is the answer to the i^th query.
A subarray is a contiguous sequence of elements in an array.
The value of |x| is defined as:
xifx >= 0.-xifx < 0.
nums = [1,3,4,8], queries = [[0,1],[1,2],[2,3],[0,3]][2,1,4,1]nums = [4,5,2,2,7,10], queries = [[2,3],[0,2],[0,5],[3,5]][-1,1,1,3]Constraints
- 2 <= nums.length <= 10^5
- 1 <= nums[i] <= 100
- 1 <= queries.length <= 2 * 10^4
- 0 <= li < ri < nums.length