List Every Upstream Dependency for Each AWS Service

Last updated: November 29, 2026

Quick Overview

Given a directed acyclic call graph where an edge (u, v) means service v depends on service u, return for every service the sorted list of all services it depends on directly or transitively.

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

0

0

0 solved


Given a directed acyclic call graph where an edge (u, v) means service v depends on service u, return for every service the sorted list of all services it depends on directly or transitively.

Blast-radius analysis matters at AWS: when a foundational service degrades, teams need to know everything downstream. The interviewer tests whether you propagate ancestor sets in topological order and reason honestly about the output-sensitive cost.

What the Interviewer Expects
  • Process nodes in topological order so a node's ancestors are complete before use
  • Union the parent's ancestors plus the parent into each child
  • Return sorted lists
  • Discuss the O(n^2) worst case output size
  • Offer the alternative of DFS from each node
Key Topics to Cover
topological sort
transitive closure
DAG
set propagation
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 answer the reverse question: everything downstream of a service?
  • If n is 100k, how would you compress the sets (bitsets, reachability labels)?
  • How would you support adding new edges online?
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: n services and edges (u, v) where v depends on u. The graph is acyclic. Output: list res with res[i] = sorted ancestors of i....

High-Level Design

Ancestors of v = union over each direct dependency u of ({u} plus ancestors of u). This recurrence needs u finalized first, which a topological order provides. With Kahn's algorithm, when we pop u eve...


Submit Your Answer
Markdown supported