Purge Every Revoked Device Token From a Linked Session List

Last updated: November 29, 2026

Quick Overview

Active sessions for a Google account are kept in a singly linked list of device tokens. Remove every node whose token equals a given revoked token and return the new head.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

0

0 solved


Active sessions for a Google account are kept in a singly linked list of device tokens. Remove every node whose token equals a given revoked token and return the new head.

A quick phone screen problem in an account security framing. The interviewer checks that you handle runs of matching nodes at the head and back to back in the middle, which is where most candidates drop a node or skip one.

What the Interviewer Expects
  • Use a dummy node so matching nodes at the head are handled uniformly
  • Only advance the predecessor pointer when the next node is kept
  • Handle consecutive matches without skipping any
  • Return dummy.next, which may be None
  • Mention the recursive version and its stack cost
Key Topics to Cover
linked list
deletion
sentinel node
in-place filtering
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
  • Remove every token in a set of revoked tokens.
  • Sessions are shared by other threads. How do you make removal safe?
  • Remove matches from a circular linked list instead.
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: head of a singly linked list and a token value bad.
  • Output: head of the list with every node whose value equals bad unlinked.
  • O(1) extra space, one pass....
High-Level Design

Put a dummy node in front of the head and walk with a pointer prev that always points at a node we are keeping. Look at prev.next: if it matches, unlink it by skipping over it and do not move `pre...


Submit Your Answer
Markdown supported