A constellation of satellites each broadcasts an integer beacon code, and ground control computes the constellation's combined signature as the bitwise XOR of every satellite's beacon code. Ground control wants the combined signature to equal a specific target signature k. To adjust it, a calibration operation may be applied any number of times: each calibration selects exactly one satellite and flips exactly one bit (from 0 to 1, or from 1 to 0) in that satellite's beacon code. Determine the minimum number of calibrations needed so that the XOR of all beacon codes equals k.
Line 1: two space-separated integers n and k — the number of satellites and the target signature.
Line 2: n space-separated integers beacon_1 ... beacon_n, the current beacon code of each satellite.
A single integer: the minimum total number of single-bit flips needed so that the XOR of all beacon codes equals k.
Example 1
Input
2 1 2 1
Expected
1
Explanation
The XOR of beacon codes 2 (binary 10) and 1 (binary 01) is 3 (binary 11). Comparing to the target k=1 (binary 01), only the higher bit differs, so exactly 1 bit flip on any one satellite's code fixes the combined signature.
Example 2
Input
3 0 1 2 3
Expected
0
Explanation
The XOR of 1, 2, and 3 is 0, which already equals the target k=0, so 0 calibrations are needed.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →