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
November 29, 20260
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
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- 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 ProblemsSample 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...