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
Coding & Algorithms
Software Engineer
Amazon
November 29, 2026
Software Engineer
Online Assessment
Coding & Algorithms
Easy

0

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
topological order
permutation check
position index
graph validation
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 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 Problems
Sample 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:

  1. Reject if order is not a permutation of 0..n-1. 2...

Submit Your Answer
Markdown supported