Find the Lone Session Token Without a Matching Logout
Last updated: November 29, 2026
Quick Overview
Every login token in a list appears exactly twice (once at login, once at logout) except one token that never logged out. Return that token in linear time and constant extra space.
Meta
November 29, 20260
0
0 solved
Every login token in a list appears exactly twice (once at login, once at logout) except one token that never logged out. Return that token in linear time and constant extra space.
A common warm-up in Meta phone screens, framed around pairing login and logout events in session logs. The interviewer wants to see whether you reach past a hash set to the XOR trick and can explain why it works.
What the Interviewer Expects
- Start with a hash-set or counter baseline and state its O(n) space
- Explain XOR properties: self-inverse, commutative, identity 0
- Write the one-pass XOR solution in O(1) space
- Trace a small example by hand
- Discuss what breaks if the input guarantee is violated
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 every token appears three times except one?
- What if two tokens are unmatched instead of one?
- How would you do this over a stream split across many machines?
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: a non-empty list of non-negative integer token IDs. Every ID appears exactly twice except one, which appears once. Output: the single ID. Constraints to confirm: list can be large (millions of ...
High-Level Design
XOR has three properties that make this trivial: a ^ a = 0, a ^ 0 = a, and XOR is commutative and associative. If we XOR every token together, each paired token cancels with its partner regardless...