Number of Unique XOR Triplets I
Real-world version: Relay Panel Fault CodesThe statement here is our own: the same inputs, outputs and technique.
A cabinet holds n relay panels in a row. Panel i carries the stamp stamps[i], and the stamps are exactly the whole numbers from 1 to n, each used once, in some order.
A technician raises a fault code by selecting three panels and combining their stamps with the bitwise XOR operation. The three selections are made independently, so the same panel may be selected two or three times, and the order of the selections does not matter.
Return how many different fault codes can be raised.
Examples
Example 1
- Input
- stamps = [3, 4, 2, 5, 1]
- Output
- 8
Selecting the panels stamped 1, 2 and 3 raises the code 0, and selecting the panels stamped 4, 5 and 3 raises the code 2. Over all selections 8 different codes come up.
Example 2
- Input
- stamps = [7, 5, 6, 8, 2, 1, 4, 3]
- Output
- 16
Selecting the panels stamped 8, 1 and 7 raises the code 14, and over all selections 16 different codes come up.
Example 3
- Input
- stamps = [3, 9, 5, 1, 6, 8, 4, 7, 2]
- Output
- 16
Selecting the panel stamped 5 all three times raises the code 5, and selecting the panels stamped 9, 8 and 2 raises the code 3. In all 16 different codes come up.
Constraints
- 1 <= stamps.length == n <= 10^5
- 1 <= stamps[i] <= n
- stamps is a permutation of the whole numbers from 1 to n.
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def distinct_fault_codes(stamps: list[int]) -> int:public int distinctFaultCodes(int[] stamps)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 16 test cases: 16 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's
More on the same topics
- Missing NumberReal-world version: Unclaimed Badge NumberEasy
- Total Hamming DistanceReal-world version: Differing Flag Bits Across RegistersMedium
- Maximize Score After N OperationsReal-world version: Retiring Blades In Paired SessionsHard
- Number of Ways to Assign Edge Weights IIReal-world version: Odd Weightings on Many RunsHard