class Solution { public boolean[] isArraySpecial(int[] nums, int[][] queries) { int n = nums.length; int m = queries.length; //Processing: Create a parityMisMatch array boolean[] parityMismatch = new boolean[n-1]; for(int i = 0; i < n-1; i++) parityMismatch[i] = (nums[i] % 2 == nums[i+1] % 2); //Create the prefix sum of mismatches int[] prefix = new int[n]; for(int i = 1; i < n; i++) prefix[i] = prefix[i-1] + (parityMismatch[i-1] ? 1 : 0); //Process the queries boolean[] result = new boolean[m]; for(int i = 0; i < m; i++) { int from = queries[i][0]; int to = queries[i][1]; // If there's any mismatch in the range [from, to - 1], the subarray is not special result[i] = (from == to) || (prefix[to] - prefix[from] == 0); } return result; } }