Sort Items by Groups Respecting Dependencies
A hard-tier problem at 66% community acceptance, tagged with Depth-First Search, Breadth-First Search, Graph. Reported in interviews at Citadel and 0 others.
You're asked to sort items within groups while respecting item-to-item dependencies. This is a hard graph problem that combines topological sort with group constraints, and Citadel has asked it. Most candidates see the graph part but miss that you're doing topological sort twice: once between groups, once within groups. The acceptance rate sits around 66%, which sounds forgiving until you're in the assessment and realize the naive approach fails. StealthCoder catches the two-pass pattern instantly if you freeze up during the live OA.
Companies that ask "Sort Items by Groups Respecting Dependencies"
Sort Items by Groups Respecting Dependencies is the kind of problem that decides whether you pass. StealthCoder reads the problem on screen and surfaces a working solution in under 2 seconds. Invisible to screen share. The proctor sees nothing. Built by an Amazon engineer who realized the OA tests how well you memorized 200 problems, not how well you code.
Get StealthCoderThe trick is recognizing this isn't a single topological sort. You need to build a group dependency graph (items in the same group form edges; items in different groups create edges between groups), then sort groups topologically, then sort items within each group topologically. Most candidates try one pass and get stuck. The pitfall: treating all dependencies the same. If item A depends on item B and they're in the same group, that's a local constraint. If they're in different groups, you need to infer a group-level dependency. Breadth-First Search or Depth-First Search both work, but you must handle cycles and track visited state carefully. If you hit this pattern cold in an assessment and can't connect the two-level sort idea, StealthCoder surfaces a working solution invisibly while you think.
Pattern tags
You know the problem.
Make sure you actually pass it.
Sort Items by Groups Respecting Dependencies recycles across companies for a reason. It's hard-tier, and most candidates blank under the timer. StealthCoder is the hedge: an AI overlay invisible during screen share. It reads the problem and surfaces a working solution in under 2 seconds. Built by an Amazon engineer who realized the OA tests how well you memorized 200 problems, not how well you code. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Sort Items by Groups Respecting Dependencies interview FAQ
Is this really a hard problem or just tedious?+
It's hard because of the abstraction layer. The actual mechanics are Topological Sort and Graph, both familiar, but the problem forces you to apply topological sort at two different scopes simultaneously. That's where the difficulty sits, not in raw complexity.
Do I need Depth-First Search or Breadth-First Search?+
Either works. DFS is cleaner for this pattern because you can detect cycles and build sort order in a single traversal. BFS using Kahn's algorithm also works if you precompute in-degrees. Pick whichever you code faster under time pressure.
What happens if there's a cycle in the dependencies?+
Return an empty result or signal an error, depending on the problem statement. The assessment will clarify. Detecting cycles is standard in topological sort: if you see a node in your current DFS path, you have a cycle. Both DFS and BFS approaches can catch this.
Does this actually come up at other companies?+
The problem is reported from Citadel. Group-constrained topological sort is niche. You're unlikely to see this exact variant often, which is why it's the kind of hard problem that trips up unprepared candidates in a live OA.
What's the biggest gotcha?+
Confusing item-level dependencies with group-level dependencies. Many candidates build one graph and fail. You need to track which items affect which groups, then sort groups, then sort within groups. Skipping that two-level thinking burns time fast.
Want the actual problem statement? View "Sort Items by Groups Respecting Dependencies" on LeetCode →