Code RoomPackage install order
MediumPrep Room Coding #1061

Package install order

CodingCode quality & reviewAlgorithms & data structuresMid–Senior~25 min

A package manager must compute an install order. You're given a list of package names and a list of dependency pairs [a, b] meaning package a depends on b (so b must be installed before a). Return a valid install order such that every dependency is installed before the package that needs it. When several packages are simultaneously installable, install the lexicographically smallest first to make the result deterministic. If the dependencies contain a cycle (no valid order exists), return an empty list. Dependency pairs referencing unknown packages are ignored.

Implement
install_order(packages: list[str], deps: list[list[str]]) → list[str]
Examples
in[["app","lib","core"],[["app","lib"],["lib","core"]]]out["core","lib","app"]
What a strong answer looks like

State your approach and its time/space complexity out loud before you optimize. Handle the edge cases (empty input, duplicates, overflow), and say why you chose this over the brute force. Green tests are the floor, not the grade.

0:00 of about 25 min
InputExpectedGot
[["app","lib","core"],[["app","lib"],["lib","core"]]]["core","lib","app"]not run yetsample