Flag Shipments Whose Tracking Events Break the Status Lifecycle

Last updated: November 29, 2026

Quick Overview

Tracking events arrive as (shipment_id, timestamp, status) possibly out of order. Using the allowed lifecycle CREATED to PICKED to PACKED to SHIPPED to OUT_FOR_DELIVERY to DELIVERED, with CANCELLED allowed before SHIPPED and DELAYED allowed after SHIPPED (returning to SHIPPED or OUT_FOR_DELIVERY), return each shipment's final status or INVALID if any transition is illegal.

Amazon
Coding & Algorithms
Software Engineer
Amazon
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


Tracking events arrive as (shipment_id, timestamp, status) possibly out of order. Using the allowed lifecycle CREATED to PICKED to PACKED to SHIPPED to OUT_FOR_DELIVERY to DELIVERED, with CANCELLED allowed before SHIPPED and DELAYED allowed after SHIPPED (returning to SHIPPED or OUT_FOR_DELIVERY), return each shipment's final status or INVALID if any transition is illegal.

An Amazon technical screen question modeled on the package tracking pipeline. The interviewer checks that you represent the lifecycle as data (an adjacency map), sort per shipment by time, and think about duplicates and out-of-order delivery of events.

What the Interviewer Expects
  • Encodes the lifecycle as an allowed-transitions map
  • Groups events by shipment and sorts by timestamp
  • Requires the first event to be CREATED
  • Treats repeated identical status as a no-op
  • Discusses late or duplicate events in a real stream
Key Topics to Cover
state machine
validation
grouping and sorting
event processing
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
  • Events arrive as a live stream: how do you handle one that is late by an hour?
  • Add a new status without changing code.
  • How would you report which transition failed?
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: list of (shipment_id, ts, status). Output: dict shipment_id to final status or 'INVALID'. First event must be CREATED. Repeating the same status consecutively is allowed (duplicate scans). Term...

High-Level Design

Define ALLOWED as a dictionary from state to the set of legal next states. Bucket events by shipment, sort each bucket by timestamp, and walk the events: if the status equals the current one, skip i...


Submit Your Answer
Markdown supported