Deterministic Package Install Order With Cycle Reporting

Last updated: November 29, 2026

Quick Overview

Given a manifest mapping each package to the packages it requires, return an install order where every package comes after its requirements, choosing the alphabetically smallest ready package at each step, and if a cycle exists report one concrete cycle path.

Replit
Coding & Algorithms
Software Engineer
Replit
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

0

0

0 solved


Given a manifest mapping each package to the packages it requires, return an install order where every package comes after its requirements, choosing the alphabetically smallest ready package at each step, and if a cycle exists report one concrete cycle path.

Replit installs dependencies for users automatically through its package tooling, and a reproducible order matters so two runs of the same Repl behave the same. The interviewer checks a correct topological sort, deterministic tie breaking, and a useful error message rather than just returning False.

What the Interviewer Expects
  • Includes packages that only appear as requirements
  • Uses Kahn's algorithm with a min-heap for determinism
  • Detects a cycle by counting processed nodes
  • Extracts an actual cycle path for the error message
  • Ignores duplicate requirement entries
Key Topics to Cover
topological sort
Kahn's algorithm
heap
cycle detection
dependency resolution
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • How would you install independent packages in parallel with at most k workers?
  • How do version constraints change this into a resolution problem?
  • How would you cache results so re-running install after adding one package is fast?
  • What should happen to packages not involved in the cycle?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements

Input deps: {pkg: [required pkgs]}. Output a list with requirements first. Ties are broken alphabetically so output is reproducible. On a cycle, raise with a path like a -> b -> c -> a....

High-Level Design

Build reverse edges from each requirement to its dependents and track how many unmet requirements each package has. Repeatedly pop the smallest package with zero unmet requirements. If fewer packages ...


Submit Your Answer
Markdown supported

Related Questions