Can All Files Compile?
Updated
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[][]) → booleanExamples
Example 1
files = ["main","util","base"]dependencies = [["util"],["base"],[]]return = trueCompile base first, then util, then main.
Example 2
files = ["a","b"]dependencies = [["b"],["a"]]return = falseEach file waits for the other, so neither can compile first.
Example 3
files = ["app"]dependencies = [["lib"]]return = falselib is not among the available files.
Constraints
0 <= files.length <= 200, anddependencies.length = files.length.- File identifiers are distinct.
- Every identifier contains
1to24English 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 Onsite Interview questions
- Most Frequent Call Path From Function Trace LogsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Design Search Autocomplete SystemPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Candy Crush Grid Matching and GravityPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Topological Sort with Secondary OrderingPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Most Frequent Call Stack Per ThreadPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Count and Score Distinct Hat AssignmentsONSITE INTERVIEW · Seen Sep 2026
- Rate Limiter Sliding Window With Per-Entity LimitsPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Most Frequent Call Path in Interleaved LogsONSITE INTERVIEW · Seen Aug 2026
- Grid Pathfinding with Obstacles (DFS)PHONE SCREEN · ONSITE INTERVIEW · Seen Jun 2026
- Maximize Distance to Closest Person — Return the SeatONSITE INTERVIEW · Seen Jun 2026
Similar questions at other companies
- Merge Event PreferencesAirbnb · PHONE SCREEN · ONSITE INTERVIEWAirbnb interview questions
- Course ScheduleAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Course ScheduleOracle · ONSITE INTERVIEWOracle interview questions
- Package Install OrderVerily · ONSITE INTERVIEW
- Course SchedulePlaud · ONSITE INTERVIEW
- Course Schedule Cycle DetectionGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
- Lexicographically Smallest Topological OrderByteDance · PHONE SCREEN · ONSITE INTERVIEWByteDance interview questions
- Evaluate Formulas with Cycle DetectionInstacart · PHONE SCREEN · ONSITE INTERVIEWInstacart interview questions
- Lexicographically Smallest Course OrderLinkedIn · ONSITE INTERVIEWLinkedIn interview questions
- Audit Discounted Category AncestorsFaire · ONSITE INTERVIEW