FastPrepCan All Files Compile?

Can All Files Compile?

Roblox logoRoblox● MediumNEW GRADONSITE INTERVIEW
Learn

Problem statement

You are given unique file identifiers in files. The parallel array dependencies describes the files that each file needs: dependencies[i] lists every direct dependency of files[i].

A file can compile after all its dependencies have compiled. Determine whether all supplied files can compile. A missing dependency or a circular dependency makes this impossible.

For this exercise, assume identifiers are case-sensitive and only files named in files are available. Repeating a dependency name adds no extra requirement. Return true when every file can compile and false otherwise. An empty file list returns true.

Function

canCompileFiles(files: String[], dependencies: String[][]) → boolean

Examples

Example 1

files = ["main","util","base"]dependencies = [["util"],["base"],[]]return = true

Compile base first, then util, then main.

Example 2

files = ["a","b"]dependencies = [["b"],["a"]]return = false

Each file waits for the other, so neither can compile first.

Example 3

files = ["app"]dependencies = [["lib"]]return = false

lib is not among the available files.

Constraints

  • 0 <= files.length <= 200, and dependencies.length = files.length.
  • File identifiers are distinct.
  • Every identifier contains 1 to 24 English letters, digits, underscores, hyphens or periods.
  • The total number of dependency entries is at most 2000.
  • Dependency identifiers may be absent from files, repeated within a row, or equal to the file itself.

More Roblox problems

See Roblox hiring insights
public boolean canCompileFiles(String[] files, String[][] dependencies) {
    // write your code here
}
files["main","util","base"]
dependencies[["util"],["base"],[]]
expectedtrue
Checking account…