Find the Event ID That Appears Once While Others Appear Three Times

Last updated: November 29, 2026

Quick Overview

In a telemetry batch where every event ID appears exactly three times except one that appears once, find that ID in linear time and constant extra space.

Microsoft
Coding & Algorithms
Software Engineer
Microsoft
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


In a telemetry batch where every event ID appears exactly three times except one that appears once, find that ID in linear time and constant extra space.

A Microsoft technical screen bit manipulation question that extends the well-known XOR trick. The interviewer checks whether you can reason per bit position (counts mod 3) and, for a stronger answer, express it as a small two-variable state machine.

What the Interviewer Expects
  • Explain why plain XOR does not work for triples
  • Count each bit position modulo 3
  • Or track ones and twos with a bitwise state machine
  • Handle negative IDs correctly
  • Achieve O(n) time and O(1) space
Key Topics to Cover
bit manipulation
XOR
state machines
modular counting
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • Generalize to every element appearing k times except one.
  • What if two IDs appear once and the rest twice?
  • How would you handle this when the batch streams across many machines?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Input is a non-empty list of integers (possibly negative, 32-bit range). Exactly one value occurs once and every other value occurs exactly three times. Return the single value using O(1) extra memory...

High-Level Design

Look at one bit position at a time. Across all numbers, that bit's count is 3k plus 0 or 1, the extra coming from the unique number. So the unique number's bit is the column count mod 3. A direct vers...


Submit Your Answer
Markdown supported