Verify a Proposed Deployment Order for Dependent CloudFormation Stacks
Last updated: November 29, 2026
Quick Overview
Given n CloudFormation stacks, a list of (before, after) dependency pairs, and a proposed deployment order, return whether the order deploys every stack exactly once and never deploys a stack before one it depends on.
Amazon
November 29, 20260
0
0 solved
Given n CloudFormation stacks, a list of (before, after) dependency pairs, and a proposed deployment order, return whether the order deploys every stack exactly once and never deploys a stack before one it depends on.
A warm-up in the Amazon online assessment style, framed around infrastructure-as-code tooling where stacks export values other stacks import. The interviewer checks that you validate the input as a permutation and check constraints in linear time instead of simulating a full topological sort.
What the Interviewer Expects
- Confirm the order is a permutation of 0..n-1 before checking dependencies
- Map each stack to its position in one pass
- Check every dependency edge in O(1) using positions
- Run in O(n + m) time
- Name the edge cases: missing stack, duplicate stack, self-dependency
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- How would you return the first violated dependency so the CLI can print a helpful error?
- What changes if some stacks can deploy in parallel and the order is a list of waves?
- How would you produce a valid order when the proposed one fails?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Inputs: n stacks labeled 0..n-1, deps as (before, after) pairs, and order. Output: True only if order contains every stack once and every before appears earlier than its after. Clarify...
High-Level Design
We do not need to build a graph or run Kahn's algorithm. An order is a valid topological order exactly when every edge points forward in it. So:
- Reject if
orderis not a permutation of 0..n-1. 2...