Find the Two Upload IDs Missing Their Confirmation Event

Last updated: November 29, 2026

Quick Overview

Each video upload emits a start event and a confirmation event with the same non-negative integer ID, so every ID appears twice in the log except two uploads that never confirmed. Find those two IDs in linear time using O(1) extra memory.

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

0

0

0 solved


Each video upload emits a start event and a confirmation event with the same non-negative integer ID, so every ID appears twice in the log except two uploads that never confirmed. Find those two IDs in linear time using O(1) extra memory.

TikTok technical screens like bit manipulation questions with a systems flavor, here reconciling upload events at the edge where memory is tight. The interviewer checks whether you know the XOR cancellation trick and can extend it from one unpaired value to two by splitting on a differing bit.

What the Interviewer Expects
  • Starts from the hash set solution and explains why it uses O(n) memory
  • Uses XOR to cancel pairs
  • Isolates a differing bit with x & -x and explains why it works
  • Partitions into two groups that each contain one answer
  • Notes the assumption that every other ID appears exactly twice
Key Topics to Cover
bit manipulation
XOR properties
two's complement
constant space algorithms
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
  • What if the unconfirmed uploads number exactly three?
  • What if each normal ID appears three times instead of twice?
  • The log is too large for one machine; how do you combine partial XORs?
  • How would you handle the realistic case where duplicates and retries break the exactly-twice assumption?
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

A list of non-negative integers where all but two values occur exactly twice and those two occur once each and differ. Return them sorted. Linear time, constant extra memory. The easy answer, a set wh...

High-Level Design

XOR is associative, commutative and x ^ x = 0, so XOR of the whole log equals a ^ b for the two answers. Since a != b, that value has at least one set bit, and at that bit exactly one of a or b ...


Submit Your Answer
Markdown supported