Order Agent Journey Steps With Dependencies and Report Cycles
Last updated: November 29, 2026
Quick Overview
An agent journey is a set of named steps plus pairs (before, after) meaning one step must run before another. Return the lexicographically smallest valid order, or if none exists, return one cycle of steps that causes the conflict.
Sierra
November 29, 20260
0
0 solved
An agent journey is a set of named steps plus pairs (before, after) meaning one step must run before another. Return the lexicographically smallest valid order, or if none exists, return one cycle of steps that causes the conflict.
Sierra lets customers describe agent behavior as steps such as greet, verify identity, look up order and issue refund, and a misconfigured dependency must be explained, not just rejected. The interviewer checks Kahn's algorithm, deterministic tie-breaking with a heap, and producing a useful error.
What the Interviewer Expects
- Build adjacency lists and in-degrees
- Use a min-heap to get the lexicographically smallest order
- Detect a cycle when fewer steps are emitted than exist
- Extract an actual cycle rather than just saying one exists
- Explain the complexity including the heap factor
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 return all steps that are blocked by the cycle, not just the cycle?
- How would you allow steps that can run in parallel and compute the minimum number of stages?
- How would you validate this incrementally as a user edits the journey in a UI?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Steps are unique strings, dependencies reference known steps. Output ("ok", order) where among all valid orders we pick the lexicographically smallest, or ("cycle", [s1, s2, ...]) where s1 must pr...
High-Level Design
Kahn's algorithm repeatedly removes a step with no remaining prerequisites. Using a min-heap for the ready set always picks the smallest available name, which yields the smallest order. If the heap em...