All problems
0514MediumArrayMathBit Manipulation

Relay Panel Fault Codes

Tracked in this browser only
Write code

Trains the technique from

LeetCode 3513Number of Unique XOR Triplets I

This is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.

Same function shape, different story and different numbers.

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 is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.

Python
def distinct_fault_codes(stamps: list[int]) -> int:
Java
public int distinctFaultCodes(int[] stamps)
September 7
Apply