Detect Invalid Document Lifecycle Transitions in an Event Log
Last updated: November 29, 2026
Quick Overview
Given a document lifecycle as a list of allowed state transitions and a time-ordered log of (document id, target state) events, return each document whose history contains a disallowed transition and the index of the first bad event.
Veeva Systems
November 29, 20260
0
0 solved
Given a document lifecycle as a list of allowed state transitions and a time-ordered log of (document id, target state) events, return each document whose history contains a disallowed transition and the index of the first bad event.
Vault documents move through configurable lifecycles such as Draft, In Review, Approved, Effective and Superseded, and a quality or regulatory audit needs to find documents that skipped a step. This warm-up checks whether the candidate can model a state machine cleanly, track per-entity state, and ask about defaults like the initial state.
What the Interviewer Expects
- Models the lifecycle as an adjacency map from state to allowed next states
- Tracks current state per document, defaulting to the lifecycle's initial state
- Reports only the first invalid event per document and stops evaluating it afterwards
- Runs in a single pass, O(E + T) time
- Asks whether a rejected event changes state (it should not)
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 every invalid event instead of only the first one?
- Lifecycles differ by document type; how does the function change when each event carries a type?
- How would you also flag documents that never reached a terminal state such as Effective?
- How would you express the same check as a SQL query over an audit trail table?
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: allowed as (from, to) pairs, an initial state, and events as (doc_id, to_state) in time order. Output: a map doc_id -> index of its first disallowed event. A document that is never touche...
High-Level Design
Build a dictionary state -> set(next states) once. Keep state[doc], defaulting to the initial state. For each event, look up whether target is in the allowed set of the current state. If yes, ad...