3755. Find Maximum Balanced XOR Subarray Length Medium

@problem@discussion
#Array#Hash Table#Bit Manipulation#Prefix Sum



1/**
2 * [3755] Find Maximum Balanced XOR Subarray Length
3 *
4 * Given an integer array nums, return the length of the longest <span data-keyword="subarray-nonempty">subarray</span> that has a bitwise XOR of zero and contains an equal number of even and odd numbers. If no such subarray exists, return 0.
5 *  
6 * <strong class="example">Example 1:
7 * <div class="example-block">
8 * Input: <span class="example-io">nums = [3,1,3,2,0]</span>
9 * Output: <span class="example-io">4</span>
10 * Explanation:
11 * The subarray [1, 3, 2, 0] has bitwise XOR 1 XOR 3 XOR 2 XOR 0 = 0 and contains 2 even and 2 odd numbers.
12 * </div>
13 * <strong class="example">Example 2:
14 * <div class="example-block">
15 * Input: <span class="example-io">nums = [3,2,8,5,4,14,9,15]</span>
16 * Output: <span class="example-io">8</span>
17 * Explanation:
18 * The whole array has bitwise XOR 0 and contains 4 even and 4 odd numbers.
19 * </div>
20 * <strong class="example">Example 3:
21 * <div class="example-block">
22 * Input: <span class="example-io">nums = [0]</span>
23 * Output: <span class="example-io">0</span>
24 * Explanation:
25 * No non-empty subarray satisfies both conditions.
26 * </div>
27 *  
28 * Constraints:
29 * 
30 * 	1 <= nums.length <= 10^5
31 * 	0 <= nums[i] <= 10^9
32 * 
33 */
34pub struct Solution {}
35
36// problem: https://leetcode.com/problems/find-maximum-balanced-xor-subarray-length/
37// discuss: https://leetcode.com/problems/find-maximum-balanced-xor-subarray-length/discuss/?currentPage=1&orderBy=most_votes&query=
38
39// submission codes start here
40
41impl Solution {
42    pub fn max_balanced_subarray(nums: Vec<i32>) -> i32 {
43        0
44    }
45}
46
47// submission codes end
48
49#[cfg(test)]
50mod tests {
51    use super::*;
52
53    #[test]
54    fn test_3755() {
55    }
56}
57

Back
© 2026 bowen.ge All Rights Reserved.