Validate Play Store Order Lifecycle Transitions in an Event Log
Last updated: November 29, 2026
Quick Overview
Orders move through states CREATED, PAID, SHIPPED, DELIVERED, plus CANCELLED and REFUNDED, under a fixed transition table. Given an interleaved event log of (order_id, new_state) tuples, return the set of order IDs that ever make an illegal transition.
0
0
0 solved
Orders move through states CREATED, PAID, SHIPPED, DELIVERED, plus CANCELLED and REFUNDED, under a fixed transition table. Given an interleaved event log of (order_id, new_state) tuples, return the set of order IDs that ever make an illegal transition.
A Google phone screen question framed around Play Store or Google Store order processing. It checks that you can encode a finite state machine as data, keep per-entity state in a map, and reason about what the first event for an order must be.
What the Interviewer Expects
- Encode allowed transitions as a dictionary of sets, not nested ifs
- Track the current state per order ID in a hash map
- Treat a first event that is not CREATED as illegal
- Keep processing other orders after one fails
- State O(n) time
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 report the first offending event index per order?
- How would you handle out-of-order events that arrive late from different services?
- What changes if the table is loaded from config and can be updated at runtime?
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: a list events of (order_id, state) tuples in arrival order. Legal transitions: CREATED to PAID or CANCELLED, PAID to SHIPPED or REFUNDED, SHIPPED to DELIVERED, DELIVERED to REFUNDED. The fi...
High-Level Design
The machine is pure data: ALLOWED = {state: set_of_next_states}, with a virtual None start state that can only go to CREATED. Keep current[order_id]. For each event, look up the current state (d...