Special Array II: Efficient Subarray Parity Check
Preprocess array to mark parity changes, then use prefix sum array to check if all pairs in query have different parity.
3152. Special Array II Difficulty: Medium Topics: Array, Binary Search, Prefix Sum An array is considered special if every pair of its adjacent elements contains two numbers with different parity. You are given an array of integer nums and a 2D integer matrix queries, where for queries[i] = [fromi, toi] your task is to check that subarray1 nums[fromi..toi] is special or not. Return an array of booleans answer such that answer[i] is true if nums[fromi..toi] is special. Example 1: Input: nums = [3,4,1,2,6], queries = [[0,4]] Output: [false] Explanation: The subarray is [3,4,1,2,6]. 2 and 6 are...