You are given an integer array nums and a list queries where each queries[i] = [l, r] is a 0-indexed inclusive range.
For each query, determine whether every value in nums[l..r] is pairwise distinct. Values are pairwise distinct when no value appears more than once in that range.
Return an array with one entry per query, in the same order as queries: 1 if the corresponding range is pairwise distinct, or 0 otherwise.
Examples
Example 1
Input: nums = [1,2,1,3], queries = [[0,1],[0,2],[1,3]]
Output: [1,0,1]
Explanation: nums[0..1] = [1,2] has no repeated value, so the answer is 1. nums[0..2] = [1,2,1] repeats the value 1, so the answer is 0. nums[1..3] = [2,1,3] has no repeated value, so the answer is 1.
Example 2
Input: nums = [5], queries = [[0,0]]
Output: [1]
Explanation: A range containing a single value is always pairwise distinct.
Example 3
Input: nums = [4,4,4], queries = [[0,2],[1,2],[2,2]]
Output: [0,0,1]
Explanation: nums[0..2] = [4,4,4] repeats 4, so the answer is 0. nums[1..2] = [4,4] repeats 4, so the answer is 0. nums[2..2] = [4] has a single value, so the answer is 1.
Constraints
1≤nums.length≤105
1≤queries.length≤105
0≤l≤r<nums.length for each [l, r] in queries
1≤nums[i]≤109
Loading editor...
Run checks the sample cases; Submit runs every case.
Samples 3
Custom 0
passedwrong answertime limiterrorran, no expected valuenot run