Remove Cancelled Stops From a Multi-Stop Route List

Last updated: November 29, 2026

Quick Overview

A multi-stop ride is stored as a singly linked list of stops, each with a cancelled flag. Remove every cancelled stop in place and return the new head of the route.

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

0

0

0 solved


A multi-stop ride is stored as a singly linked list of stops, each with a cancelled flag. Remove every cancelled stop in place and return the new head of the route.

A linked list warm-up in the style of Uber's phone screens, based on riders adding and removing stops mid-trip. The interviewer checks the dummy head pattern and that you never lose the rest of the list while unlinking.

What the Interviewer Expects
  • Uses a dummy node so removing the head is not a special case
  • Unlinks nodes without skipping consecutive cancelled stops
  • Works in one pass with O(1) extra space
  • Returns None when every stop is cancelled
  • Tests head, tail and consecutive removals
Key Topics to Cover
Linked lists
Dummy node
In-place deletion
Pointers
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
  • How would you do it recursively, and what is the stack risk?
  • What if the route is a doubly linked list?
  • How would you also return the removed stops in order?
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 list of Node(val, next) where val is a (stop_id, cancelled) pair. Output: head of the list with cancelled stops removed, order preserved. O(1) extra space....

High-Level Design

Attach a dummy node in front of the head. Walk with prev starting at the dummy. If prev.next is cancelled, bypass it with prev.next = prev.next.next and do not advance prev, because the new `p...


Submit Your Answer
Markdown supported