Find the Two Unmatched Trip IDs in a Start and End Log
Last updated: November 29, 2026
Quick Overview
A log lists trip IDs, and every completed trip appears exactly twice (start and end). Exactly two trips are missing their end event and appear once. Return those two IDs in O(n) time and O(1) extra space.
Uber
November 29, 20260
0
0 solved
A log lists trip IDs, and every completed trip appears exactly twice (start and end). Exactly two trips are missing their end event and appear once. Return those two IDs in O(n) time and O(1) extra space.
Uber's technical screens like reconciliation problems that look like real trip-event audits. The interviewer wants the XOR insight, then the trick of splitting the IDs on a differing bit, with a clear argument for why it works.
What the Interviewer Expects
- Notes that XOR of everything cancels paired IDs
- Explains why the combined XOR is nonzero
- Splits IDs into two groups by one differing bit
- Meets O(1) extra space without a hash set
- Returns results in a deterministic order
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- What if exactly one trip is unmatched?
- What if every completed trip appears three times instead of twice?
- How would you do this if the log is too big for memory and spread across shards?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: list of non-negative integers where all values appear twice except two distinct values that appear once. Output: the two singles sorted ascending. Constraint: O(1) extra space, so a counting di...
High-Level Design
XOR of the whole list equals a ^ b, because each paired ID cancels itself. Since a != b, this value has at least one set bit, and at that bit position a and b differ. Partition every ID by whe...