Distinct Window Queries
MediumArrays ยท Google
Given an integer array readings and a list windows of [left, right] index pairs, return a list of booleans with one entry per window.
An entry is True when the readings at positions left through right, both inclusive, are pairwise different, and False when some value appears more than once in that range.
Example 1
- Input:
- readings = [4, 7, 4, 9, 1, 7], windows = [[0, 1], [0, 2], [2, 5]]
- Output:
- [True, False, True]
- Explanation
- Positions 0 to 2 hold 4, 7, 4, so 4 repeats; positions 2 to 5 hold 4, 9, 1, 7, all different.
Example 2
- Input:
- readings = [5, 5, 5], windows = [[1, 1]]
- Output:
- [True]
Example 3
- Input:
- readings = [3, 8, 1, 3], windows = [[0, 3], [1, 2]]
- Output:
- [False, True]
Constraints
1 <= readings.length <= 100000-10^9 <= readings[i] <= 10^91 <= windows.length <= 1000000 <= left <= right < readings.lengthfor every window