Back to problems

Recursive Class Dependency Ordering

Algorithm · Vanta · Medium

Given n classes and their dependency links, determine a valid order for initializing or building the classes. Classes use the IDs 0 through n - 1. A dependency [a, b] states that a requires b, so b must be processed earlier than a. Your topological sort must be implemented with recursive DFS. Kahn's algorithm with an in-degree queue must not be used as the primary approach. When the dependency graph has a cycle, print IMPOSSIBLE. When several valid orders are possible,…

Checking your access…