All problems
0228MediumArrayBit Manipulation

Once-Logged Drift Reading

Tracked in this browser only
Write code

Trains the technique from

LeetCode 137Single Number II

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 calibration bench mirrors every drift reading it takes into three separate journals, so the merged dump carries three copies of each reading the bench produced. One reading was keyed in by hand before mirroring was switched on, and that reading sits in the dump on its own.

The merged dump arrives as the integer array readings. Return the reading that occurs only once. Drift may run either side of zero, so a reading can be negative.

Work in time proportional to the length of readings, and hold only a fixed number of extra values while you do it.

Examples

Example 1

Input
readings = [4, 7, 4, 4, 9, 7, 7, 12, 12, 12]
Output
9

Counting copies: 4 appears three times, 7 appears three times and 12 appears three times, while 9 appears once.

Example 2

Input
readings = [-5, 8, 8, 8]
Output
-5

The dump holds three copies of 8 and a single -5, and the hand-keyed reading is the negative one.

Example 3

Input
readings = [10, 10, 1, 10, 1, 1, -6]
Output
-6

The dump carries three copies of 10 and three copies of 1, and -6 is the reading with a single copy.

Constraints

  • 1 <= readings.length <= 3 * 10^4
  • -2^31 <= readings[i] <= 2^31 - 1
  • Every reading in readings occurs exactly three times, except one reading that occurs exactly once

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 once_logged_reading(readings: list[int]) -> int:
Java
public int onceLoggedReading(int[] readings)
September 7
Apply