AmazonOA #218
Get Minimum Moves to Zero
Estimated MediumJudge-ready
Topics (AI-labelled)Bits & MathPrefix & Ranges
The array has even length. One operation chooses any 0≤L≤R<n, computes the XOR x of all elements in the range before the operation, then sets every element in the range to x simultaneously. Find the minimum number of operations to make every element zero.
Input
The first line contains an even n; the second line contains the array. The original text only specifies that n is even; this site uses 2≤n≤200000; 0≤element<2^20.
Output
Output a single integer, the answer.
Example 1
Input:
2
0 0
Output:
0
Example 2
Input:
2
3 3
Output:
1
Example 3
Input:
2
1 2
Output:
2
Example notes
The answers are 0, 1 and 2. Third example: 1,2→3,3→0,0.
Editorial
Loading solution…