OP 29 April, 2022 - 06:43 PM
You are given an array A of even length N consisting of non-negative integers. You need to make each element of the array equal to zero, by doing some number of moves (possibly zero).
In a single move, you can choose two integers l and r such that 1 ≤ l ≤ r ≤ N. Let x = A[l] ⊕ A[l+1] ⊕ A[l+2] ... A[r], where ⊕ represents xor operator. Then, replace the whole subarray with x. In other words, assign A[i] = x for l ≤ i ≤ r.
Print the minimum number of moves required to make the entire array zero.
Sample Input:
2
2
2 2
4
7 1 2 0
Sample Output:
1
2
In a single move, you can choose two integers l and r such that 1 ≤ l ≤ r ≤ N. Let x = A[l] ⊕ A[l+1] ⊕ A[l+2] ... A[r], where ⊕ represents xor operator. Then, replace the whole subarray with x. In other words, assign A[i] = x for l ≤ i ≤ r.
Print the minimum number of moves required to make the entire array zero.
Sample Input:
2
2
2 2
4
7 1 2 0
Sample Output:
1
2