CodePark/ problems / Package installer
START PRACTICINGPRACTICE
Coding problem · Practical class design › Graphs and dependencies

Package installer

mediumabout 40 minutes in an interview

Build a small package manager as a PackageInstaller class.

new PackageInstaller(registry) takes an object. It maps each package name to the list of packages it directly needs, for example { app: ["web", "db"], web: ["http"], db: [], http: [] }. Nothing is installed at the start.

Input: pm = new PackageInstaller({ app: ["web", "db"], web: ["http"], db: [], http: [] }) pm.install("app") Output: ["http", "web", "db", "app"]
Input: pm.install("web") Output: []already installed

It comes in 3 parts, each building on the last: Install, Uninstall, Install order and loops.