Topological Sort of Cloud Resource Dependencies

Last updated: December 9, 2025

Quick Overview

Given cloud resources with dependencies (VPCs contain subnets, subnets contain instances, instances use security groups), produce a valid deletion order that respects dependencies. Handle circular dependencies gracefully.

Wiz
Coding & Algorithms
Software Engineer
Wiz
December 9, 2025
Software Engineer
Technical Phone Screen
Coding & Algorithms
Medium

9

4

2,453 solved


Given cloud resources with dependencies (VPCs contain subnets, subnets contain instances, instances use security groups), produce a valid deletion order that respects dependencies. Handle circular dependencies gracefully.

Cloud resource cleanup and decommissioning requires deleting resources in the right order. You cannot delete a VPC before deleting the subnets inside it, and you cannot delete a subnet before deleting the instances in it. This is a classic topological sort problem with the real-world twist of handling circular dependencies that sometimes exist in cloud environments.

What the Interviewer Expects
  • Implement topological sort using Kahn's algorithm (BFS) or DFS
  • Detect and handle circular dependencies instead of crashing
  • Return a valid deletion order (reverse topological order)
  • Handle multiple valid orderings correctly
Key Topics to Cover
Topological sorting
Kahn's algorithm (BFS-based)
Cycle detection
Dependency graph modeling
Parallel execution ordering
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
  • What if some resources can be deleted in parallel? How would you maximize parallelism?
  • How would you handle a circular dependency between a security group and an instance?
  • Can you modify your solution to handle weighted dependencies (some deletions take longer)?
Sharpen Your Skills on Codemia

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

Practice DSA Problems
Sample Answer
Problem Analysis

This problem involves creating a valid deletion order for cloud resources that have dependencies, which is a classic topological sorting problem. We will use Kahn's algorithm, which is based on BFS, b...

Approach
  1. Graph Representation: Model the resources as a directed graph where nodes represent resources and edges represent dependencies. For instance, if a subnet (S2) depends on a VPC (V1), there will ...

Submit Your Answer
Markdown supported

Related Questions