← Snowflake Interview Insights

Snowflake·Software Engineer·Technical Phone Screen·Intermediate

Intermediate
Jul 2026

Summary

Snowflake SWE interview with two coding problems back to back. The graph one was manageable but the rate limiter problem had a tricky sliding window constraint that took me a while to reason through cleanly.

Questions Asked (3)

Q1

Given n courses and a list of prerequisite pairs, determine whether it's possible to complete all courses (i.e., detect if the prerequisite graph contains a cycle).

Algorithms & Data Structures
Author's notes

Classic cycle detection in a directed graph.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the problem as a directed graph where each course is a node and each prerequisite pair is a directed edge, then apply cycle detection using either DFS with coloring (white/gray/black states) or Kahn's algorithm (topological sort via BFS with in-degree tracking). If a cycle exists, it's impossible to complete all courses; otherwise it is possible. Clearly articulate the time and space complexity of your chosen approach before coding.

Pro tip: Mention both DFS-based and BFS-based (Kahn's algorithm) approaches upfront, then explain your preference — interviewers at companies like Snowflake appreciate candidates who demonstrate awareness of trade-offs, such as BFS being more intuitive for iterative environments and DFS being elegant recursively but risking stack overflow on very large graphs.

1. Clarify & Model the Problem

Restate the problem as cycle detection in a directed graph, where nodes are courses and directed edges represent prerequisites. Confirm edge cases such as n=0, no prerequisites, or duplicate pairs.

2. Choose & Explain Your Algorithm

Select either DFS with 3-color node states (unvisited/visiting/visited) or BFS topological sort using in-degree counts (Kahn's algorithm). Briefly justify your choice by comparing their trade-offs in readability, iterative vs. recursive style, and suitability for large inputs.

3. Build the Graph

Construct an adjacency list from the prerequisite pairs and, if using Kahn's algorithm, compute the in-degree for each node. Walk through a small example to validate your graph construction.

4. Implement Cycle Detection

For DFS, traverse each unvisited node and flag a cycle if you revisit a 'visiting' (gray) node. For BFS, process nodes with in-degree zero, decrement neighbors' in-degrees, and check if all n nodes were processed at the end.

5. Analyze Complexity & Edge Cases

State that both approaches run in O(V + E) time and O(V + E) space, where V = n courses and E = number of prerequisite pairs. Discuss edge cases like disconnected graph components, self-loops, and isolated nodes.

Key Points to Mention

  • Directed graph modeling: courses as nodes, prerequisites as directed edges
  • DFS with 3-color states (unvisited/visiting/visited) to detect back edges indicating cycles
  • Kahn's BFS topological sort: cycle exists if processed node count < n after BFS completes
  • Time complexity O(V + E) and space complexity O(V + E) for both approaches
  • Handling disconnected components by iterating over all nodes as potential starting points
  • Edge cases: self-loops (a course that is its own prerequisite), duplicate prerequisite pairs, and n=0 or empty prerequisite list

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q2

Follow-up on the course scheduling problem: if it is possible to finish all courses, what is the minimum number of semesters needed, given that you can take any number of courses per semester as long as prerequisites are satisfied?

Algorithms & Data Structures
Author's notes

This is just the longest path in a DAG, or equivalently the number of levels in the topological order.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Model the problem as finding the longest path in a DAG (Directed Acyclic Graph), since the minimum number of semesters equals the length of the critical path through the prerequisite chain. Use topological sort (BFS/Kahn's algorithm) and track the earliest semester each course can be taken by propagating the maximum depth level from prerequisites. The answer is simply the maximum level assigned to any course.

Pro tip: Explicitly mention that this is equivalent to finding the 'critical path' — a concept from project scheduling — which signals systems-level thinking and impresses interviewers at data-infrastructure companies like Snowflake where pipeline scheduling is a real-world concern.

1. Reframe the Problem

Recognize that since you can take unlimited courses per semester, the bottleneck is purely the longest prerequisite chain. The minimum semesters equals the length of the longest path in the prerequisite DAG.

2. Build the Graph and In-Degree Array

Construct an adjacency list representing course dependencies and compute the in-degree (number of prerequisites) for each course node. This sets up Kahn's BFS-based topological sort.

3. BFS Level-by-Level (Topological Sort)

Initialize a queue with all courses that have zero in-degree (no prerequisites) and assign them to semester 1. Process the queue level by level — each level represents one semester — decrementing in-degrees and enqueuing newly unblocked courses.

4. Track Maximum Semester Depth

Maintain a 'semester' array where semester[i] = max(semester[prerequisite]) + 1 for each course, ensuring each course is scheduled only after all its prerequisites are completed. The answer is the maximum value in this array.

5. Analyze Complexity and Edge Cases

State time complexity O(V + E) and space O(V + E). Discuss edge cases: a single chain of n courses requires n semesters, while completely independent courses require only 1 semester.

Key Points to Mention

  • Longest path in a DAG as the core insight — minimum semesters equals the critical path length
  • Kahn's algorithm (BFS topological sort) for level-by-level processing, where each BFS level maps to one semester
  • Dynamic programming on the DAG: semester[course] = max(semester[prereq] for all prereqs) + 1
  • Why DFS-based topological sort also works: assign depth as the maximum recursion depth from any source node
  • Time complexity O(V + E) and space complexity O(V + E), where V = courses and E = prerequisites
  • Real-world analogy to critical path method (CPM) in project management or pipeline scheduling

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q3

You're given a non-decreasing array of request timestamps. A rate limiter drops a request if it exceeds 3 requests at the same timestamp, or if processing it would push the count of processed requests in any 10-second sliding window above 20. Return the timestamps of all dropped requests in order.

Algorithms & Data StructuresSystem Design
Author's notes

This one tripped me up more than I expected.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Simulate the rate limiter by iterating through the sorted timestamps and applying two independent drop conditions: a per-timestamp counter check and a sliding window count check using a deque or two-pointer approach. Track dropped requests separately so they don't pollute the sliding window of processed requests. Clearly separate the two rule evaluations to keep the logic clean and testable.

Pro tip: Emphasize that dropped requests must NOT be counted toward the sliding window total — only successfully processed requests count. This subtle distinction is easy to miss and is likely an intentional trap in the problem; catching it signals strong attention to spec details, which is critical in systems like Snowflake's data pipelines.

1. Clarify the Rules and Edge Cases

Restate both drop conditions clearly: (1) more than 3 requests share the exact same timestamp, and (2) accepting a request would cause more than 20 processed requests within any 10-second window [t-9, t]. Ask whether 'same timestamp' resets after 3 drops or continues dropping all extras.

2. Choose the Right Data Structures

Use a deque (or queue) to maintain the sliding window of processed request timestamps, enabling O(1) eviction of timestamps outside the 10-second window. Use a counter or dictionary to track how many requests have been seen at the current timestamp for the per-timestamp rule.

3. Implement the Two-Rule Check

For each incoming timestamp, first check the per-timestamp count — if this is the 4th or more request at this timestamp, mark it dropped. Otherwise, evict stale entries from the deque (those with timestamp < current - 9), then check if the deque size is already 20; if so, drop the request.

4. Update State Only for Accepted Requests

Only append the timestamp to the sliding window deque and increment the per-timestamp counter when a request is accepted, not dropped. This ensures dropped requests don't inflate the window count or the timestamp frequency count.

5. Validate with Test Cases

Walk through at least two examples: one where the per-timestamp rule triggers (e.g., four requests at t=5) and one where the sliding window rule triggers (e.g., 21 requests spread across 10 seconds). Also test the boundary condition where the window is exactly 10 seconds wide (e.g., timestamps 1 and 10 should be in the same window).

Key Points to Mention

  • Dropped requests are excluded from the sliding window count — only processed (accepted) requests count toward the 20-request limit.
  • The sliding window is defined over a 10-second range [t-9, t], so timestamps exactly 9 seconds apart are within the same window (clarify inclusive/exclusive boundaries).
  • A deque enables efficient O(1) amortized eviction of out-of-window timestamps as the array is traversed left to right.
  • The per-timestamp rule and sliding window rule are independent — a request can be dropped by either condition, and both must be checked in the correct order.
  • Since the input array is non-decreasing, a two-pointer or monotonic deque approach is optimal, yielding overall O(n) time complexity.
  • Mention that this mirrors real-world rate limiter design (e.g., token bucket vs. sliding window log algorithms) to demonstrate system design awareness relevant to Snowflake's infrastructure context.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.