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
Coding & Algorithms
Software Engineer
Meta
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

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
XOR
Bit manipulation
Constant space
Session logs
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 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 Problems
Sample 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...


Submit Your Answer
Markdown supported