Trains the technique from
LeetCode 260Single Number IIIThis 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 rig reads every probe twice during a sweep and appends the probe's signed drift value to one shared log, so a value that belongs to a fully read probe turns up in the log exactly twice. Two probes worked loose partway through the sweep and were read only once, so their drift values turn up exactly once each. No two probes share a drift value.
Given the sweep log drifts, return the two values that appear exactly once. The two may be returned in either order.
The rig has almost no working memory, so use only a constant amount of extra space beyond the log itself, and read the log a constant number of times.
Example 1
The values -5 and 12 each show up twice, while 9 and 7 each show up once.
Example 2
Only 4 is logged twice, so the loose probes are the ones that reported 6 and 10.
Example 3
The log holds nothing but the two single readings, so both of them are loners.
The values you return may be in any order.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def unmatched_drifts(drifts: list[int]) -> list[int]:public int[] unmatchedDrifts(int[] drifts)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.