Package Dependency Order
Updated
Problem statement
You are given package dependency pairs and a target package. Each pair [package, dependency] means the package depends on that dependency.
Return an order in which to install the target package and all of its transitive dependencies so that every dependency appears before the package that needs it.
If there is a cyclic dependency among packages needed by the target package, return an empty array.
Multiple valid orders may exist. To make the answer unique, use this deterministic rule: process dependencies in the order they appear in the input pairs.
Function
packageInstallOrder(dependencies: String[][], target: String) → String[]Examples
Example 1
dependencies = [["A","B"],["A","C"],["B","D"],["B","E"],["B","F"],["C","F"],["F","G"],["H","I"],["H","J"],["J","G"]]target = "A"return = ["D","E","G","F","B","C","A"]The order installs D, E, and F before B; installs G before F; installs F before C; and installs both B and C before A.
More Amazon Onsite Interview questions
- Number of IslandsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Cheapest Flights Within K StopsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Course SchedulePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Course Schedule IIPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Dungeon GameONSITE INTERVIEW · Seen Nov 2026
- Integer BreakONSITE INTERVIEW · Seen Nov 2026
- LFU CacheONSITE INTERVIEW · Seen Nov 2026
- LRU Cache for Query ResultsPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Count Adjacent Symbol Pairs for BPEONSITE INTERVIEW · Seen Nov 2026
- First Non-Repeating CharacterOA · ONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Task Build Order and File-Change RerunsVanta · PHONE SCREEN
- Course SchedulePlaud · ONSITE INTERVIEW
- All Halfway Courses Across Course TracksCrunchyroll · PHONE SCREENCrunchyroll interview questions
- Course Schedule Cycle DetectionGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
- Audit Discounted Category AncestorsFaire · ONSITE INTERVIEW
- Course ScheduleNykaa · PHONE SCREENNykaa interview questions
- Detect a Cycle in a Directed GraphMakeMyTrip.com · ONSITE INTERVIEWMakeMyTrip.com interview questions
- Effective Role PrivilegesSnowflake · PHONE SCREENSnowflake interview questions
- Course ScheduleFlexTrade · ONSITE INTERVIEWFlexTrade interview questions
- Remove Redundant Task DependenciesMicrosoft · ONSITE INTERVIEWMicrosoft interview questions