Single Number III
Real-world version: Unmatched Sensor DriftsThe statement here is our own: the same inputs, outputs and technique.
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.
Examples
Example 1
- Input
- drifts = [12, -5, 9, -5, 12, 7]
- Output
- [7, 9]
The values -5 and 12 each show up twice, while 9 and 7 each show up once.
Example 2
- Input
- drifts = [6, 10, 4, 4]
- Output
- [6, 10]
Only 4 is logged twice, so the loose probes are the ones that reported 6 and 10.
Example 3
- Input
- drifts = [-31, 18]
- Output
- [-31, 18]
The log holds nothing but the two single readings, so both of them are loners.
Constraints
- 2 <= drifts.length <= 3 * 10^4
- -2^31 <= drifts[i] <= 2^31 - 1
- Every value in drifts appears exactly twice, except for exactly two values that each appear exactly once.
The values you return may be in any order.
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 unmatched_drifts(drifts: list[int]) -> list[int]:public int[] unmatchedDrifts(int[] drifts)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 11 test cases: 11 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