Microservice Deployment Order
Updated
Problem statement
A platform must deploy n services labeled from 0 to n - 1.
Each pair [service, prerequisite] in dependencies means that service cannot start until prerequisite is running.
Return the lexicographically smallest valid deployment order. At each step, deploy the smallest labeled service whose prerequisites are all running. If the dependencies contain a cycle, return an empty array.
Function
deploymentOrder(n: int, dependencies: int[][]) → int[]Examples
Example 1
n = 4dependencies = [[1,0],[2,0],[3,1],[3,2]]return = [0,1,2,3]Service 0 is ready first; services 1 and 2 then become ready, so label 1 is selected before label 2.
Example 2
n = 3dependencies = [[0,1],[1,2],[2,0]]return = []The three services form a cycle, so no valid deployment order exists.
Constraints
1 <= n <= 10^50 <= dependencies.length <= 2 * 10^5- Every dependency contains two different labels in
[0, n - 1]. - Dependency pairs are unique.
More Goldman Sachs Onsite Interview questions
- Knight Probability in ChessboardONSITE INTERVIEW · Seen Nov 2026
- Best Average Student ScorePHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Meeting RoomsPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Minimum Meeting Rooms Without a Sweep LineONSITE INTERVIEW · Seen Oct 2026
- First Non-Repeating CharacterPHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Root of the Largest TreePHONE SCREEN · ONSITE INTERVIEW · Seen Oct 2026
- Dungeon HealthONSITE INTERVIEW · Seen Sep 2026
- Insert, Delete, And Get Random In Constant TimeONSITE INTERVIEW · Seen Sep 2026
- Least Recently Used CacheONSITE INTERVIEW · Seen Sep 2026
- Staircase Search In A Sorted MatrixONSITE INTERVIEW · Seen Sep 2026
Similar questions at other companies
- Merge Event PreferencesAirbnb · PHONE SCREEN · ONSITE INTERVIEWAirbnb interview questions
- Course Schedule IIAmazon · PHONE SCREEN · ONSITE INTERVIEW
- Lexicographically Smallest Topological OrderByteDance · PHONE SCREEN · ONSITE INTERVIEWByteDance interview questions
- Merge Subsequences Into a Consistent Total OrderGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions
- Topological Sort with Secondary OrderingRoblox · PHONE SCREEN · ONSITE INTERVIEWRoblox interview questions
- Lexicographically Smallest Course OrderLinkedIn · ONSITE INTERVIEWLinkedIn interview questions
- ETL Pipeline SchedulerUnity · ONSITE INTERVIEW
- Course Schedule IIWalmart · ONSITE INTERVIEWWalmart interview questions
- Task Order With PrerequisitesDoorDash · PHONE SCREEN · ONSITE INTERVIEWDoorDash interview questions
- Task Order with DependenciesNotion · ONSITE INTERVIEWNotion interview questions