Search⌘ K
AI Features

Compilation Order

Explore how to identify and organize class dependencies to find the proper compilation order. This lesson helps you apply topological sort to solve problems involving compilation dependencies, enabling you to manage tasks, course schedules, and related challenges efficiently.

Statement

There are a total of nn classes labeled with the English alphabet (AA, BB, CC, and so on). Some classes are dependent on other classes for compilation. For example, if class BB extends class AA, then BB has a dependency on AA. Therefore, AA must be compiled before BB.

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.
  • 00 \leq dependencies.length 676\leq 676
  • dependencies[i].length =2= 2
  • All dependency pairs should be unique.

Examples

In the above examples, the arrows represent the relationship between these classes. For example, the arrow ACA \rightarrow C shows that CC extends AA, and therefore, CC is dependent on AA.

Understand the problem

Let’s take a moment to make sure you’ve correctly understood the problem. The quiz below helps us to check if you’re solving the correct problem:

Compilation Order

1.

Given the following array of dependencies, what is the order of compilation of classes?

Select all that apply.

dependencies = [A, B], [B, C], [A, D] Multi-select

A.

[A, B, C, D]

B.

[C, A, B, D]

C.

[C, B, D, A]

D.

[D, C, B, A]


1 / 3

Figure it out!

We have a game for you to play. Rearrange the logical building blocks to develop a clearer understanding of how to solve this problem.

Sequence - Vertical
Drag and drop the cards to rearrange them in the correct sequence.

1
2
3
4
5
6

Try it yourself

Implement your solution in main.go in the following coding playground. We have provided some useful code templates in the other file that you may build on to solve this problem.

Go
usercode > main.go
package main
func findOrder(dependencies [][]rune) []rune {
// Replace this placeholder return statement with your code
return make([]rune, 0)
}
Compilation Order