Solution: Compilation Order
Explore how to apply topological sorting to solve the compilation order problem by modeling class dependencies as a graph. Understand how to build the graph, identify sources, and use BFS traversal to produce a valid compilation sequence. Learn to detect cycles and evaluate algorithm efficiency to confidently solve dependency-related interview questions.
Statement
There are a total of classes labeled with the English alphabet (, , , and so on). Some classes are dependent on other classes for compilation. For example, if class extends class , then has a dependency on . Therefore, must be compiled before .
Given a list of the dependency pairs, find the order in which the classes should be compiled.
Constraints:
- Class name should be an uppercase character.
-
dependencies.length dependencies[i].length