Answer many range queries about whether a subarray is special, using a precomputed parity boundary summary.
You are given an integer array nums and multiple queries. For each query [l, r], determine whether the subarray nums[l...r] is special.
A subarray is special if every pair of adjacent elements in it alternates in parity: one is even, the next is odd, then even, and so on, for the entire subarray.
In other words, for every index i with l <= i < r, nums[i] and nums[i + 1] must have different parity.
Return the answer for every query.
nums.[l, r] representing a subarray range.i-th value indicates whether nums[l...r] is special for query i.1 <= nums.length0 <= l <= r < nums.lengthExample 1
Input
nums = [3, 4, 1, 2, 7], queries = [[0, 4], [1, 3], [2, 2]]
Output
[true, true, true]
Explanation
The full array alternates parity at every step. The subarray [4,1,2] also alternates. A one-element subarray is always special.
Example 2
Input
nums = [2, 4, 6, 1], queries = [[0, 2], [1, 3]]
Output
[false, false]
Explanation
[2,4,6] has adjacent pairs with the same parity, so it is not special. [4,6,1] also contains the same-parity pair [4,6].
Premium problem context
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.