Practice Minimum Absolute Difference Queries
Read the task, work through the examples, and check your approach against the constraints. Use the original LeetCode task for coding and submissions.
Problem Statement
For each inclusive query [l,r], return the smallest absolute difference between two unequal values in nums[l..r]. If the subarray has only one distinct value, return -1. Return answers in query order. Absolute difference is the nonnegative distance between the two values.
Source: Minimum Absolute Difference Queries on LeetCode. Use the original task for its coding environment and submissions.
Examples
# Example 1
Input
nums = [1,3,4,8], queries = [[0,1],[1,2],[2,3],[0,3]]
Output
[2,1,4,1]
# Example 2
Input
nums = [4,5,2,2,7,10], queries = [[2,3],[0,2],[0,5],[3,5]]
Output
[-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
Related LeetCode Problems
Practice more problems similar to Minimum Absolute Difference Queries.
Review your practice with PhantomCodeAI
After trying the problem yourself, use the app to discuss your approach, complexity, and edge cases.