Problem
You are given an integer array nums of length n and q queries. Each query is a pair [l, r] (0-indexed, inclusive).
A subarray nums[l..r] is called alternating parity if for every index i with l < i <= r, nums[i] and nums[i-1] have different parity (one is even and the other is odd).
Task
For each query [l, r], determine whether nums[l..r] is alternating parity. Return a boolean array (or an array of true/false answers) of length q.
Input/Output
-
Input:
nums
,
queries
-
Output: list of booleans, one per query
Constraints (reasonable interview assumptions)
-
1 <= n, q <= 2*10^5
-
Values in
nums
can be negative or positive; parity is based on
abs(nums[i]) % 2
.
Notes
-
A subarray of length 0 or 1 is always alternating parity.
-
You should aim for near
O(n + q)
time overall.