XOR Equal | CodeChef Solution

Hello coders, today we are going to solve XOR Equal CodeChef Solution whose Problem Code is PALINT.

Task

You are given an array A consisting of N integers and an integer X. Your goal is to have as many equal integers as possible in the array. To achieve this goal, you can do the following operation:

Choose an index i (1 ≤ i N) and set Ai = AiX, where ⊕ denotes the bitwise xor operation.

Find the maximum number of equal integers you can have in the final array and the minimum number of operations to obtain these many equal integers.

Input Format

  • The first line of the input contains a single integer T denoting the number of test cases. The description of T test cases follows.
  • Each test case contains two lines of input.
  • The first line of each test case contains two space-separated integers N, X.
  • The second line of each test case contains N space-separated integers A1, A2, . . . , AN.

Output Format

For each test case, print a single line containing two space-separated integers – first, the maximum number of equal integers in the final array and second, the minimum number of operations to achieve these many equal integers.

Constraints

  • 1 ≤ T ≤ 104
  • 1 ≤ N ≤ 105
  • 0 ≤ X ≤ 109
  • 0 ≤ Ai ≤ 109
  • The sum of N over all test cases does not exceed 5⋅105

Subtasks

Subtask #1 (100 points): Original constraints

Sample Input 1

 3
 3 2
 1 2 3
 5 100
 1 2 3 4 5
 4 1
 2 2 6 6

Sample Output 1

 2 1
 1 0
 2 0

Explanation

Test case 1: One way to obtain 2 equal integers is to set A1 = A1 ⊕ 2 = 1 ⊕ 2 = 3. So, the array becomes [3, 2, 3]. There is no way to obtain 3 equal integers in the final array.

Test case 2: There is no way to obtain more than one equal integer.

Solution – XOR Equal

C++

Python

Java

Disclaimer: The above Problem (XOR Equal) is generated by CodeChef but the Solution is Provided by CodingBroz. This tutorial is only for Educational and Learning Purpose.

Leave a Comment

Your email address will not be published. Required fields are marked *