Array
3702. Longest Subsequence With Non-Zero Bitwise XOR
The whole-array XOR decides the answer, and it is only ever n or n-1. XOR every element together: if that total is non-zero, the entire array is already a valid subsequence, so the answer is n. If the total is zero, dropping one non-zero element leaves an XOR equal to that element — itself non-zero — so the answer is n-1.
Loading…