values of integers between 1 and 100, and a list of queries ranges, where ranges[i] = [lo, hi].
For each query, look at the slice of the array from index lo to index hi inclusive and find the smallest difference |a - b| over pairs of its elements with **different** values. If every element of the slice is the same (including a slice of a single element), the answer to that query is -1.
Return the answers in query order.values=[6, 2, 9, 2, 5], ranges=[[0, 1], [1, 3], [2, 4], [0, 4]] → [4, 7, 3, 1]
[6, 2] → 4; [2, 9, 2] → 7 (the two 2s are equal and do not count); [9, 2, 5] → 3; across the whole array 5 and 6 are closest → 1.
values=[3, 3, 3], ranges=[[0, 2], [1, 2]] → [-1, -1]
All numbers are equal, so there is no pair of different values: both answers are -1.
values=[6, 2, 9, 2, 5], ranges=[[0, 1], [1, 3], [2, 4], [0, 4]]
[4, 7, 3, 1]
Run checks the first 3 tests in your browser. Submit checks all 89 tests on the server, hidden ones included.