Validate Order Status Transition Logs Against a State Machine

Last updated: November 29, 2026

Quick Overview

An order moves through states like CREATED, PACKED, SHIPPED, OUT_FOR_DELIVERY, DELIVERED, CANCELLED and RETURNED with a fixed set of allowed transitions. Given a time ordered event log for many orders, return the IDs of orders with an invalid transition.

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

0

0

0 solved


An order moves through states like CREATED, PACKED, SHIPPED, OUT_FOR_DELIVERY, DELIVERED, CANCELLED and RETURNED with a fixed set of allowed transitions. Given a time ordered event log for many orders, return the IDs of orders with an invalid transition.

A practical Flipkart phone screen question that mirrors how order management services guard against out of order or duplicate events. The interviewer checks that you model the state machine as data, track per order state, and think about events for unknown orders.

What the Interviewer Expects
  • Represent allowed transitions as a dictionary of sets
  • Track the current state per order in a hash map
  • Treat the first event for an order as valid only if it is CREATED
  • Report each bad order once, in a deterministic order
  • Discuss idempotent duplicate events
Key Topics to Cover
state machines
simulation
hash map
event 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 tolerate exact duplicate events delivered twice by Kafka?
  • Events can arrive slightly out of order; how would you handle that?
  • How would you add a rule like 'cancellation only allowed before SHIPPED'?
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 (order_id, new_state) in time order, interleaved across orders.
  • Allowed transitions are fixed (confirm them with the interviewer; e.g. failed delivery can return `OUT_FOR_DELIVERY...
High-Level Design

Encode the state machine as a table from current state to the set of legal next states, with None meaning 'not seen yet', whose only legal next state is CREATED. Keep a map of order to current sta...


Submit Your Answer
Markdown supported