#3630
Partition Array for Maximum XOR and AND
grandmaster · 2255 · lc hard +32 · 17.6% accepted · 31 likes · top 1%
Description
Partition integer array nums into three (possibly empty) subsequences A, B, and C such that every element belongs to exactly one of them.
Maximize XOR(A) + AND(B) + XOR(C), where:
- XOR(arr) is the bitwise XOR of all elements (0 for empty).
- AND(arr) is the bitwise AND of all elements (0 for empty).
Return the maximum achievable value.
Code
1
2
3