Special Array II
An array is considered special if every pair of its adjacent elements contains two numbers with different parity.
You are given an array of integers nums and a 2D integer matrix queries, where for queries[i] = [fromi, toi], your task is to check whether the subarray nums[fromi..toi] is special.
Return an array of booleans answer such that answer[i] is true if nums[fromi..toi] is special, and false otherwise.
Example 1
Input
nums = [3,4,1,2,6], queries = [[0,4]]Output
[false]The subarray is [3,4,1,2,6], and 2 and 6 are both even.
Example 2
Input
nums = [4,3,1,6], queries = [[0,2],[2,3]]Output
[false,true]For [4,3,1], 3 and 1 are both odd, while [1,6] has its only adjacent pair with different parity.
Constraints
- 1 <= nums.length <= 10^5
- 1 <= nums[i] <= 10^5
- 1 <= queries.length <= 10^5
- queries[i].length == 2
- 0 <= queries[i][0] <= queries[i][1] <= nums.length - 1