Order Dynamic Table Refreshes by Upstream Dependencies

Last updated: November 29, 2026

Quick Overview

Given a set of tables and edges meaning a downstream table reads from an upstream table, return an order to refresh them so every upstream refreshes first, breaking ties alphabetically. If dependencies contain a cycle, return the tables that can never refresh.

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

0

0

0 solved


Given a set of tables and edges meaning a downstream table reads from an upstream table, return an order to refresh them so every upstream refreshes first, breaking ties alphabetically. If dependencies contain a cycle, return the tables that can never refresh.

Dynamic tables and task graphs in Snowflake refresh along a dependency DAG, so a topological sort with deterministic output is a common technical screen question. The interviewer checks Kahn's algorithm, duplicate edge handling, and what you report when the graph is not a DAG.

What the Interviewer Expects
  • Builds in-degree counts and an adjacency set, deduplicating repeated edges
  • Uses Kahn's algorithm with a min-heap for deterministic alphabetical tie-breaks
  • Detects a cycle when fewer nodes are emitted than exist
  • Reports blocked tables, including downstream tables stuck behind the cycle
  • States O((V + E) log V) complexity
Key Topics to Cover
topological sort
Kahn's algorithm
cycle detection
min-heap
DAG scheduling
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 produce refresh waves so independent tables can refresh in parallel?
  • How would you name the exact cycle rather than every blocked table?
  • If only one upstream table changed, how do you refresh just the affected subgraph?
  • How would you handle tables that appear in edges but not in the table list?
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: table names and (upstream, downstream) edges. Output: {ok: True, order} or {ok: False, blocked}. Every upstream appears before its downstream; among tables ready at the same moment, pick ...

High-Level Design

Kahn's algorithm: count incoming edges, start with all zero in-degree tables, repeatedly emit one and decrement its children. A plain queue gives some valid order; a min-heap gives the lexicographical...


Submit Your Answer
Markdown supported