Ctrl K

The Odd One Among Triples

Medium
A sensor sends readings, and each value normally arrives exactly three times, since the signal is tripled for reliability. Only one value arrived a single time. Find it. The readings come in any order. A dictionary solution is easy; try for linear time and O(1) extra memory.
Example 1
readings=[4, -1, 4, 4] → -1

4 shows up three times, -1 only once.

Example 2
readings=[7, 0, 5, 0, 7, 5, 7, 0, 5, 12] → 12

7, 0 and 5 each appear three times; 12 appears once.

Example 3
readings=[-30] → -30
Constraints
  • 1 ≤ len(readings) ≤ 3·10⁴
  • -2³¹ ≤ readings[i] ≤ 2³¹ - 1
  • Exactly one value appears once; every other value appears exactly three times
Have you seen this problem in a real interview?
Solved by0
Tried by0
Submissions0
Acceptance—
Topics
Similar problemsEvery Topping Combo MediumAll Distinct Card Hands MediumTwo Values Without a Pair MediumSpot the Extra Copy MediumWords With No Shared Letters Medium
loading Python…
Input
readings=[4, -1, 4, 4]
Expected
-1

Run checks the first 3 tests in your browser. Submit checks all 86 tests on the server, hidden ones included.