3152. Special Array II Medium

@problem@discussion
#Array#Binary Search#Prefix Sum



1/**
2 * [3152] Special Array II
3 *
4 * An array is considered special if every pair of its adjacent elements contains two numbers with different parity.
5 * 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 <span data-keyword="subarray">subarray</span> nums[fromi..toi] is special or not.
6 * Return an array of booleans answer such that answer[i] is true if nums[fromi..toi] is special.<!-- notionvc: e5d6f4e2-d20a-4fbd-9c7f-22fbe52ef730 -->
7 *  
8 * <strong class="example">Example 1:
9 * <div class="example-block">
10 * Input: <span class="example-io">nums = [3,4,1,2,6], queries = [[0,4]]</span>
11 * Output: <span class="example-io">[false]</span>
12 * Explanation:
13 * The subarray is [3,4,1,2,6]. 2 and 6 are both even.
14 * </div>
15 * <strong class="example">Example 2:
16 * <div class="example-block">
17 * Input: <span class="example-io">nums = [4,3,1,6], queries = [[0,2],[2,3]]</span>
18 * Output: <span class="example-io">[false,true]</span>
19 * Explanation:
20 * <ol>
21 * 	The subarray is [4,3,1]. 3 and 1 are both odd. So the answer to this query is false.
22 * 	The subarray is [1,6]. There is only one pair: (1,6) and it contains numbers with different parity. So the answer to this query is true.
23 * </ol>
24 * </div>
25 *  
26 * Constraints:
27 * 
28 * 	1 <= nums.length <= 10^5
29 * 	1 <= nums[i] <= 10^5
30 * 	1 <= queries.length <= 10^5
31 * 	queries[i].length == 2
32 * 	0 <= queries[i][0] <= queries[i][1] <= nums.length - 1
33 * 
34 */
35pub struct Solution {}
36
37// problem: https://leetcode.com/problems/special-array-ii/
38// discuss: https://leetcode.com/problems/special-array-ii/discuss/?currentPage=1&orderBy=most_votes&query=
39
40// submission codes start here
41
42impl Solution {
43    pub fn is_array_special(nums: Vec<i32>, queries: Vec<Vec<i32>>) -> Vec<bool> {
44        
45    }
46}
47
48// submission codes end
49
50#[cfg(test)]
51mod tests {
52    use super::*;
53
54    #[test]
55    fn test_3152() {
56    }
57}
58


Back
© 2025 bowen.ge All Rights Reserved.