Validate Order Status Transitions From an Unordered Event Log

Last updated: November 29, 2026

Quick Overview

Given a log of (timestamp, order_id, status) events that may arrive out of order, return the ids of orders whose history violates the order lifecycle state machine or never reaches a terminal state.

DoorDash
Coding & Algorithms
Software Engineer
DoorDash
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Easy

0

0

0 solved


Given a log of (timestamp, order_id, status) events that may arrive out of order, return the ids of orders whose history violates the order lifecycle state machine or never reaches a terminal state.

Every DoorDash order moves through a lifecycle (created, confirmed by the merchant, picked up by the Dasher, delivered, or cancelled), and bad transitions usually mean a bug in one of many services writing events. The interviewer checks that you model the state machine as data, sort before replaying, and make deliberate choices about duplicates and incomplete orders.

What the Interviewer Expects
  • Represent allowed transitions as a table rather than nested ifs
  • Sort events by timestamp before replaying per order
  • Decide how to treat duplicate identical events (idempotent retries)
  • Flag orders that end in a non-terminal state
  • Keep processing other orders after one is marked invalid
Key Topics to Cover
state machines
simulation
sorting
data validation
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 report the first offending event for each bad order?
  • What if two events share a timestamp and their true order is unknown?
  • How would you run this as a streaming check with late-arriving events?
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
  • States: CREATED -> CONFIRMED -> PICKED_UP -> DELIVERED, with CANCELLED allowed from CREATED or CONFIRMED.
  • The first event of an order must be CREATED.
  • An exact repeat of the current status...
High-Level Design

Encode the lifecycle as ALLOWED[current] = set(next states), with None meaning not yet seen. Sort all events by timestamp, then replay them while keeping state[order_id]. On each event either ig...


Submit Your Answer
Markdown supported