[Solution] One-XOR Deletions CodeChef Solution
Problem
Chef has with him an array of length . In one move, he can delete any element from .
Find the minimum number of deletions Chef must make so that the following condition holds:
- Let denote the resulting array, and be the length of .
- Then, for every .
Here, denotes the bitwise XOR operation.
For example, and are valid final arrays, while and are not (because and , respectively).
Input Format
- The first line of input will contain a single integer , denoting the number of test cases.
- Each test case consists of two lines of input.
- The first line of each test case contains a single integer , denoting the length of array .
- The second line contains space-separated integers — the elements of array .
Output Format
For each test case, output on a new line the answer: the minimum number of deletions required so that the given condition is satisfied.
Explanation:
Test case : The given array already satisfies the condition, no deletions need to be done.
Test case : Chef can delete both the 's to make the array , which satisfies the condition.
Test case : Chef can use three moves as follows:
- Delete the , the array is now .
- Delete the , the array is now .
- Delete the , the array is now which satisfies the condition.
It can be verified that using two or less deletions cannot give an array that satisfies the condition.
No comments:
Post a Comment