Code Room
CodingMediumcod-g493
Subject Topological sortLevel Mid–Senior~25 minCommon in Code quality & review · Algorithms & data structures interviewsIndustries Software development

Question

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.

Vibe coding: describe the solution in plain language (or narrate it) and the coach grades your approach. Generating runnable code from your description is coming next.

Run or narrate your approach, then ask the coach.