1363. Minimum Number of Operations to Make XOR Zero

MediumBit ManipulationBit ManipulationXORGreedy

In one operation you may flip any single bit of any element of the array. Return the minimum number of operations required so that the XOR of all elements becomes zero.

Input: A JSON object {"nums": [<non-negative integers>]}.

Output: Return the minimum number of single-bit flips.

Examples

Example 1
Input: {"nums":[1,2,3]}
Output: 0
Explanation: The XOR is already 0, so no operations are needed.
Example 2
Input: {"nums":[1,2,4]}
Output: 3
Explanation: The XOR is 7 with three set bits -> 3 operations.

Constraints

Asked by

AmazonMicrosoftGoogleAdobeFlipkart
Solve this problem in the editor →