3681. Maximum XOR of Subsequences Hard
1/**
2 * [3681] Maximum XOR of Subsequences
3 *
4 * You are given an integer array nums of length n where each element is a non-negative integer.
5 * Select two <span data-keyword="subsequence-array">subsequences</span> of nums (they may be empty and are allowed to overlap), each preserving the original order of elements, and let:
6 *
7 * X be the bitwise XOR of all elements in the first subsequence.
8 * Y be the bitwise XOR of all elements in the second subsequence.
9 *
10 * Return the maximum possible value of X XOR Y.
11 * Note: The XOR of an empty subsequence is 0.
12 *
13 * <strong class="example">Example 1:
14 * <div class="example-block">
15 * Input: <span class="example-io">nums = [1,2,3]</span>
16 * Output: <span class="example-io">3</span>
17 * Explanation:
18 * Choose subsequences:
19 *
20 * First subsequence [2], whose XOR is 2.
21 * Second subsequence [2,3], whose XOR is 1.
22 *
23 * Then, XOR of both subsequences = 2 XOR 1 = 3.
24 * This is the maximum XOR value achievable from any two subsequences.
25 * </div>
26 * <strong class="example">Example 2:
27 * <div class="example-block">
28 * Input: <span class="example-io">nums = [5,2]</span>
29 * Output: <span class="example-io">7</span>
30 * Explanation:
31 * Choose subsequences:
32 *
33 * First subsequence [5], whose XOR is 5.
34 * Second subsequence [2], whose XOR is 2.
35 *
36 * Then, XOR of both subsequences = 5 XOR 2 = 7.
37 * This is the maximum XOR value achievable from any two subsequences.
38 * </div>
39 *
40 * Constraints:
41 *
42 * 2 <= nums.length <= 10^5
43 * 0 <= nums[i] <= 10^9
44 *
45 */
46pub struct Solution {}
47
48// problem: https://leetcode.com/problems/maximum-xor-of-subsequences/
49// discuss: https://leetcode.com/problems/maximum-xor-of-subsequences/discuss/?currentPage=1&orderBy=most_votes&query=
50
51// submission codes start here
52
53impl Solution {
54 pub fn max_xor_subsequences(nums: Vec<i32>) -> i32 {
55 0
56 }
57}
58
59// submission codes end
60
61#[cfg(test)]
62mod tests {
63 use super::*;
64
65 #[test]
66 fn test_3681() {
67 }
68}
69Back
© 2026 bowen.ge All Rights Reserved.