Order Ansible Automation Roles and Report Dependency Cycles
Last updated: November 29, 2026
Quick Overview
Given automation roles and their prerequisite roles, return a valid execution order, or if impossible, return the set of roles that are stuck because they sit on or behind a dependency cycle.
IBM
November 29, 20260
0
0 solved
Given automation roles and their prerequisite roles, return a valid execution order, or if impossible, return the set of roles that are stuck because they sit on or behind a dependency cycle.
Red Hat Ansible Automation Platform resolves role dependencies before running a playbook, so topological sorting with useful error reporting fits IBM and Red Hat onsite coding rounds. The interviewer looks for Kahn's algorithm and, importantly, a helpful failure output instead of just returning false.
What the Interviewer Expects
- Model prerequisites as directed edges from prerequisite to dependent
- Use Kahn's algorithm with in-degree counts
- Detect cycles when the output is shorter than the role count
- Report which roles could not be scheduled
- Keep the order deterministic for reproducible runs
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 print one actual cycle rather than all stuck roles?
- How would you run independent roles in parallel waves?
- What if a prerequisite name is misspelled and not defined as a role?
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: deps, a dictionary mapping each role to a list of prerequisite roles. Prerequisites that are not keys still count as roles with no prerequisites. Output: (order, stuck). If all roles can ru...
High-Level Design
Collect every role name, compute in-degrees (number of prerequisites) and a reverse map from prerequisite to dependents. Seed a min-heap with zero in-degree roles so ties resolve alphabetically, which...