2317. Maximum XOR After Operations Medium

@problem@discussion
#Array#Math#Bit Manipulation



1/**
2 * [2317] Maximum XOR After Operations 
3 *
4 * You are given a 0-indexed integer array nums. In one operation, select any non-negative integer x and an index i, then update nums[i] to be equal to nums[i] AND (nums[i] XOR x).
5 * Note that AND is the bitwise AND operation and XOR is the bitwise XOR operation.
6 * Return the maximum possible bitwise XOR of all elements of nums after applying the operation any number of times.
7 *  
8 * Example 1:
9 * 
10 * Input: nums = [3,2,4,6]
11 * Output: 7
12 * Explanation: Apply the operation with x = 4 and i = 3, num[3] = 6 AND (6 XOR 4) = 6 AND 2 = 2.
13 * Now, nums = [3, 2, 4, 2] and the bitwise XOR of all the elements = 3 XOR 2 XOR 4 XOR 2 = 7.
14 * It can be shown that 7 is the maximum possible bitwise XOR.
15 * Note that other operations may be used to achieve a bitwise XOR of 7.
16 * Example 2:
17 * 
18 * Input: nums = [1,2,3,9,2]
19 * Output: 11
20 * Explanation: Apply the operation zero times.
21 * The bitwise XOR of all the elements = 1 XOR 2 XOR 3 XOR 9 XOR 2 = 11.
22 * It can be shown that 11 is the maximum possible bitwise XOR.
23 *  
24 * Constraints:
25 * 
26 * 	1 <= nums.length <= 10^5
27 * 	0 <= nums[i] <= 10^8
28 * 
29 */
30pub struct Solution {}
31
32// problem: https://leetcode.com/problems/maximum-xor-after-operations/
33// discuss: https://leetcode.com/problems/maximum-xor-after-operations/discuss/?currentPage=1&orderBy=most_votes&query=
34
35// submission codes start here
36
37impl Solution {
38    pub fn maximum_xor(nums: Vec<i32>) -> i32 {
39        0
40    }
41}
42
43// submission codes end
44
45#[cfg(test)]
46mod tests {
47    use super::*;
48
49    #[test]
50    fn test_2317() {
51    }
52}
53


Back
© 2025 bowen.ge All Rights Reserved.