Snowflake logo

Snowflake Software Engineer Coding Questions

19 practice questions for Snowflake Software Engineer interviews

Snowflake software engineer interviews cover algorithms, data structures, system design, and coding problems drawn from real interview rounds.

Software Engineer Backend Engineer Frontend Engineer Full Stack Engineer Mobile Engineer Data Engineer Data Scientist ML Engineer DevOps Engineer DevOps Engineer Product Manager SRE Security Engineer Engineering Manager Data Analyst UX/UI Designer QA Engineer
coding Hard Verified Question #1

1. Pipeline Throughput Optimizer


Category: Array coding problem

Question A message-processing pipeline consists of n services that must all be traversed in sequence. The pipeline's effective throughput is...

Input: Array
Output: Integer
Want to practise this one?
Create a free account to open the full question and practise Snowflake questions with AI.
Sign up free
coding Hard Verified Question #2

2. [OA] Bounded Transition Subsequence


Category: Array coding problem
You are compressing a color run sequence. Given an array of color IDs and an integer k representing the maximum number of allowed color changes,...
Input: Array
Output: Integer
coding Medium Verified Question #3

3. [OA] Complete Vowel Substrings


Category: String coding problem
Given a string s, count the number of contiguous substrings that: 1. Consist entirely of vowel characters ('a', 'e', 'i', 'o', 'u') 2....
Input: String
Output: Integer
coding Medium Verified Question #4

4. [OA] Work Schedule Generator


Category: Graph coding problem
A factory uses a shift planning system to schedule worker hours across a 7-day week. Each day is represented as a single character in a pattern...
Input: Graph (nodes and edges)
Output: Array
coding Medium Verified Question #5

5. API Throttle Manager


Category: Sliding window coding problem
Design an APIThrottleManager for an API gateway that enforces multiple rate-limiting policies simultaneously. Each policy defines a sliding window...
Input: Integer(s)
Output: Integer
coding Medium Verified Question #6

6. Color Chain Winner


Category: Grid/matrix coding problem
You are implementing a color chain game. Two players take turns placing tokens on a grid. Each cell contains "red", "blue", or "" (empty). A...
Input: 2D grid
Output: Computed result
coding Hard Verified Question #7

7. Inherited Access Rights


Category: String coding problem
You are building an access control system for a company with n departments (numbered 0 to n-1). Departments can inherit access rights from...
Input: List
Output: Computed result
coding Medium Verified Question #8

8. Longest Prefix Router


Category: String coding problem
You are building a network packet forwarder. Given a routing table and a list of incoming packet source addresses, determine the correct gateway for...
Input: List
Output: Computed result
coding Medium Verified Question #9

9. Product Sales Ranker


Category: String coding problem
Design a ProductSalesRanker class for an e-commerce platform that tracks cumulative product sales and returns the top-ranked products on demand....
Input: List
Output: Computed result
coding Medium Verified Question #10

10. Resizable LRU Cache


Category: Trie-based coding problem
Design a ResizableLRUCache for a web server that caches integer key-value responses. The cache has a fixed capacity at creation time but can be...
Input: Integer(s)
Output: Computed result
coding Medium Verified Question #11

11. Tagged Value Store


Category: Trie-based coding problem
Design a TaggedValueStore for a configuration system that stores string keys mapped to integer values. The store supports standard CRUD operations...
Input: List
Output: Array
coding Hard Verified Question #12

12. Three Frequency Assignment


Category: Graph coding problem
You are assigning radio frequencies to a set of communication towers. To avoid interference, no two towers that directly interfere with each other...
Input: Graph (nodes and edges)
Output: Computed result
coding Hard tree #1

1. [AI Enabled Coding] Query History Guardrail Evaluator


Scenario


Snowflake customers use virtual warehouses to execute queries and inspect execution history through QUERY_HISTORY. Build a prototype that processes exported query-completion records enriched with estimated compute credits, helping platform administrators detect warehouse bursts and account-wide credit spikes; these estimates are monitoring inputs, not a reproduction of Snowflake billing. You may use an AI assistant while coding, but must verify its implementation and explain its complexity.

Part 1 — Warehouse guardrails


  • Each input record is a map of strings containing query_id, account, warehouse, finished_at, and credits. finished_at is an integer Unix timestamp in seconds; credits is a nonnegative decimal string with at most two fractional digits.

  • Process records in their input order, which can differ from timestamp order. Insert the current record before evaluating its rules. Previously emitted results never change.

  • For a current timestamp t and window length w, include only records already processed whose timestamps satisfy t - w < finished_at <= t. Previously processed records with later timestamps are excluded.

  • Warehouses are identified by the pair (account, warehouse), not by warehouse name alone.

  • Default rule WAREHOUSE_BURST: alert if the current warehouse has more than 3 queries in the last 60 seconds.

  • Default rule WAREHOUSE_CREDITS: alert if the current warehouse has more than 10.00 estimated credits in the last 300 seconds.

  • Every record contributes to history, even if it triggers an alert. Evaluate all rules independently; equality with a limit does not trigger an alert.

  • Emit one result per record in input order. Sort triggered rule IDs lexicographically. For the examples, use { "query_id": ..., "alerts": [rule_id, ...] }.


Function signature:
def evaluate_queries(records: list[dict[str, str]]):

The return type is up to the candidate; the examples specify the required information and use one canonical JSON representation.

Example 1:


Input:
{
  "records": [
    {"query_id":"q1","account":"A","warehouse":"ETL","finished_at":"1000","credits":"4.00"},
    {"query_id":"q2","account":"A","warehouse":"ETL","finished_at":"1010","credits":"4.00"},
    {"query_id":"q3","account":"A","warehouse":"ETL","finished_at":"1020","credits":"3.00"},
    {"query_id":"q4","account":"A","warehouse":"ETL","finished_at":"1030","credits":"0.00"},
    {"query_id":"q5","account":"A","warehouse":"ETL","finished_at":"1090","credits":"1.00"}
  ]
}

Output:
[
  {"query_id":"q1","alerts":[]},
  {"query_id":"q2","alerts":[]},
  {"query_id":"q3","alerts":["WAREHOUSE_CREDITS"]},
  {"query_id":"q4","alerts":["WAREHOUSE_BURST","WAREHOUSE_CREDITS"]},
  {"query_id":"q5","alerts":["WAREHOUSE_CREDITS"]}
]

Explanation: Credit totals are 4.00, 8.00, 11.00, 11.00, and 12.00. At q4, all four queries are in (970, 1030], so both default rules fire. At q5, the burst window is (1030, 1090]: q4 is exactly on the excluded boundary, leaving only q5, while all five records remain in the 300-second credit window.

Part 2 — Caller-defined policies and diagnostic alerts


Account administrators now need policies spanning multiple warehouses, and other teams need to add policies without editing the evaluator. Extend Part 1 rather than replacing its default rules.
  • Accept an additional list of string-valued maps, each containing rule_id, scope, metric, window_seconds, and limit.

  • scope is warehouse or account. Account policies aggregate all warehouses in the current record's account. Warehouse policies retain Part 1's composite warehouse identity.

  • metric is count or credits. A policy fires exactly when its metric in (t - window_seconds, t] is strictly greater than limit. Count limits are nonnegative integer strings; credit limits are nonnegative decimal strings with at most two fractional digits.

  • Defaults remain active. Policy IDs are unique and cannot equal either default ID.

  • Return all triggered policies, sorted by rule_id. Each alert now includes rule_id, scope, observed, and limit. Serialize counts as integer strings and credits with exactly two fractional digits.

  • The design must support future additions of the same kind through policy data, without adding policy-specific branches. Discuss how the return type changes before implementing the extension.

  • Do not rescan an entity's complete history for each record or discard history merely because a later timestamp has been seen. Target O(n log n + n r log n + r log r) time or better, where n is the number of records and r is the total number of policies, including defaults. The full input batch is available for preprocessing, but future input records must not contribute early.


Function signature:
def evaluate_with_policies(
    records: list[dict[str, str]],
    policies: list[dict[str, str]]
):

Example 2:


Input:
{
  "records": [
    {"query_id":"a1","account":"A","warehouse":"ETL","finished_at":"100","credits":"6.00"},
    {"query_id":"a2","account":"A","warehouse":"BI","finished_at":"110","credits":"5.00"},
    {"query_id":"a3","account":"A","warehouse":"ETL","finished_at":"120","credits":"2.00"},
    {"query_id":"a4","account":"A","warehouse":"BI","finished_at":"130","credits":"6.00"}
  ],
  "policies": [
    {"rule_id":"ACCOUNT_CREDITS","scope":"account","metric":"credits","window_seconds":"300","limit":"12.00"}
  ]
}

Output:
[
  {"query_id":"a1","alerts":[]},
  {"query_id":"a2","alerts":[]},
  {"query_id":"a3","alerts":[
    {"rule_id":"ACCOUNT_CREDITS","scope":"account","observed":"13.00","limit":"12.00"}
  ]},
  {"query_id":"a4","alerts":[
    {"rule_id":"ACCOUNT_CREDITS","scope":"account","observed":"19.00","limit":"12.00"},
    {"rule_id":"WAREHOUSE_CREDITS","scope":"warehouse","observed":"11.00","limit":"10.00"}
  ]}
]

Explanation: Account credit totals are 6.00, 11.00, 13.00, and 19.00. At a3, ETL has only 6.00 + 2.00 = 8.00, but the account exceeds 12.00. At a4, BI has 5.00 + 6.00 = 11.00, so both the account policy and default warehouse credit policy fire. Neither warehouse has more than two queries.

Example 3:


Input:
{
  "records": [
    {"query_id":"e1","account":"A","warehouse":"ETL","finished_at":"200","credits":"6.00"},
    {"query_id":"e2","account":"A","warehouse":"BI","finished_at":"210","credits":"4.00"},
    {"query_id":"e3","account":"A","warehouse":"ETL","finished_at":"190","credits":"5.00"},
    {"query_id":"e4","account":"A","warehouse":"ETL","finished_at":"220","credits":"1.00"},
    {"query_id":"e5","account":"A","warehouse":"ETL","finished_at":"280","credits":"0.00"}
  ],
  "policies": [
    {"rule_id":"ACCOUNT_BURST","scope":"account","metric":"count","window_seconds":"60","limit":"2"},
    {"rule_id":"ACCOUNT_CREDITS","scope":"account","metric":"credits","window_seconds":"300","limit":"10.00"}
  ]
}

Output:
[
  {"query_id":"e1","alerts":[]},
  {"query_id":"e2","alerts":[]},
  {"query_id":"e3","alerts":[]},
  {"query_id":"e4","alerts":[
    {"rule_id":"ACCOUNT_BURST","scope":"account","observed":"4","limit":"2"},
    {"rule_id":"ACCOUNT_CREDITS","scope":"account","observed":"16.00","limit":"10.00"},
    {"rule_id":"WAREHOUSE_CREDITS","scope":"warehouse","observed":"12.00","limit":"10.00"}
  ]},
  {"query_id":"e5","alerts":[
    {"rule_id":"ACCOUNT_CREDITS","scope":"account","observed":"16.00","limit":"10.00"},
    {"rule_id":"WAREHOUSE_CREDITS","scope":"warehouse","observed":"12.00","limit":"10.00"}
  ]}
]

Explanation: At e2, account count 2 and credits 6.00 + 4.00 = 10.00 equal their limits, so neither account policy fires. At late-arriving e3, the previously processed timestamps 200 and 210 are greater than 190 and excluded: only e3 contributes, with count 1 and credits 5.00. At e4, account count is 4, account credits are 6.00 + 4.00 + 5.00 + 1.00 = 16.00, and ETL credits are 6.00 + 5.00 + 1.00 = 12.00, triggering three policies simultaneously; ETL count is exactly 3 and does not trigger its burst rule. At e5, (220, 280] contains only e5, but the 300-second credit totals remain 16.00 and 12.00.

Notes:


  • There are at most 200,000 records and 32 total policies, including defaults; an empty record list is valid. All input fields are valid, and query IDs are unique within the batch.

  • Timestamps are nonnegative integers, windows are positive integer seconds, and equal timestamps are allowed. Only records already processed, including the current record, count toward a result.

  • Use exact decimal arithmetic or integer hundredths for credits. These are monitoring alerts, not query rejection or warehouse suspension decisions.
Want to practise this one?
Create a free account to open the full question and practise Snowflake questions with AI.
Sign up free
coding Medium tree #2

2. Tree Traversal — Implement a function to traverse a binary tree in level-order

1. Background: In the realm of data management, Snowflake processes vast amounts of structured and semi-structured data. Efficient data retrieval and organization from various sources are paramount. A binary tree traversal in level order could facilitate optimizations in query parsing and execution plans.
2. Problem statement: Write a function that performs a level-order traversal of a binary tree. The function should return the values of the nodes in level-order, where each level is processed from left to right.
3. Function/class signature:
- def level_order_traversal(root: Optional[TreeNode]) -> List[List[int]]:
4. Example 1:
- Input: root = [3,9,20,null,null,15,7]
- Output: [[3],[9,20],[15,7]]
- Explanation: The levels are traversed starting from the root (3), then moving to the next level (9 and 20), and finally to the last level (15 and 7).
5. Example 2:
- Input: root = [1]
- Output: [[1]]
- Explanation: Single-node level traversal.
6. Constraints:
- The tree may contain up to 1000 nodes.
- Node values will be integers within the range of [-1000, 1000].
coding Medium graph #3

3. Data Structures — Course Dependencies Graph

Background: Snowflake often handles complex data processing tasks that involve understanding relationships and dependencies among courses in educational data sets. Managing these efficiently is crucial for query optimization and resource allocation.
Problem statement: You need to design a function that takes a list of courses and their dependencies, returning a list of courses in a valid order. If there is a cycle in the dependencies, return an empty list. The input will be a list of pairs, where each pair represents a prerequisite relationship, such as (course_a, course_b) meaning course_b is dependent on course_a.
Function/class signature:
  • def course_order(dependencies: List[Tuple[str, str]]) -> List[str]:

Example 1:
  • Input: [('CS101', 'CS102'), ('CS102', 'CS103'), ('CS101', 'CS104')]

  • Output: ['CS101', 'CS102', 'CS103', 'CS104']

  • Explanation: CS101 must be taken before CS102, which must be taken before CS103.

Example 2:
  • Input: [('CS101', 'CS102'), ('CS102', 'CS101')]

  • Output: []

  • Explanation: There is a cycle between CS101 and CS102, so valid ordering is impossible.

Constraints:
  • The number of nodes (courses) will be at most 10^4.

  • The number of dependencies will be at most 10^4.

  • Course identifiers are unique strings.
coding Medium graph #4

4. Data Structures — Course Scheduling Cycle Detection

Background: Snowflake's architecture requires efficient scheduling of tasks that may depend on each other. Detecting cycles in dependencies is crucial for ensuring a straightforward execution order to optimize resource utilization.
Problem statement: Given a list of pairs where each pair (a, b) indicates that course a must be completed before course b, determine if you can finish all courses. If there are cycles in the dependencies, it is impossible to finish. Return true if it's possible to finish all courses, or false otherwise.
Function/class signature: def can_finish(num_courses: int, prerequisites: List[Tuple[int, int]]) -> bool
Example 1:
Input: num_courses = 2, prerequisites = [(1, 0)]
Output: True
Explanation: There are two courses and a prerequisite that allows for one course to be completed before the other, so it's possible to finish.
Example 2:
Input: num_courses = 2, prerequisites = [(1, 0), (0, 1)]
Output: False
Explanation: The prerequisites create a cycle between the two courses, making it impossible to complete.
Constraints:
  • 1 <= num_courses <= 10^5

  • 0 <= prerequisites.length <= 10^5

  • prerequisites[i] is a pair of distinct integers in the range [0, num_courses - 1].
coding Medium graph #5

5. Data Structures — Course Dependencies and Cycles

1. Background: In data-centric organizations like Snowflake, understanding course dependencies is crucial for optimizing task execution. A course can depend on another, and if not managed correctly, it might lead to cyclic dependencies that can freeze or crash a system.
2. Problem statement: You are tasked with implementing a function that determines if it is possible to finish all courses given their prerequisites. Each course is represented by an integer, and prerequisites are pairs of courses (where the second course must be completed before the first). Your function should return true if all courses can be finished, and false if there's a cycle.
3. Function/class signature:
- def can_finish(num_courses: int, prerequisites: List[List[int]]) -> bool:
4. Example 1:
- Input: num_courses = 2, prerequisites = [[1, 0]]
- Output: True
- Explanation: There are 2 courses, and you can finish course 0 first and then course 1.
5. Example 2:
- Input: num_courses = 2, prerequisites = [[1, 0], [0, 1]]
- Output: False
- Explanation: There is a cycle: you need to finish course 0 to finish course 1, but to finish course 0, you need to finish course 1.
6. Constraints:
- 1 <= num_courses <= 2000
- 0 <= prerequisites.length <= 5000
- prerequisites[i].length == 2
- 0 <= prerequisites[i][0], prerequisites[i][1] < num_courses
coding Medium graph #6

6. Graph Traversal — Detecting Course Dependencies and Cycles

Background: In Snowflake's architecture, managing dependencies and execution order for various tasks is crucial for ensuring workflows are efficient and avoid execution delays. This problem relates to the backend logic that coordinates job scheduling and execution.
Problem statement: You need to determine if it is possible to complete all courses given a list of prerequisite pairs, where a pair [a, b] means you must complete course b before course a. If there is a cycle in the prerequisite graph, it's impossible to complete all courses. Implement a function to determine if all courses can be completed.
Function signature: def can_complete_courses(num_courses: int, prerequisites: List[List[int]]) -> bool:
Example 1:
Input: num_courses = 2, prerequisites = [[0, 1]]
Output: True
Explanation: You can take course 1 and then course 0.
Example 2:
Input: num_courses = 2, prerequisites = [[0, 1], [1, 0]]
Output: False
Explanation: There is a cycle between course 0 and course 1.
Constraints:
  • 1 <= num_courses <= 2000

  • 0 <= prerequisites.length <= 5000

  • prerequisites[i].length == 2

  • All course indices are in the range [0, num_courses - 1].
coding Medium database #7

7. SQL Proficiency — finding duplicate entries

Background: In Snowflake's data warehousing service, ensuring data integrity is critical. This task involves detecting duplicate records that may arise during data ingestion or processing.
Problem statement: You are provided with a table named sales_data that contains the following columns: id, customer_id, sales_amount, and sales_date. Your goal is to write a SQL query that identifies all customer_ids with duplicate sales records. A customer is considered to be a duplicate if they have multiple entries with identical sales_date and sales_amount values.
Function/class signature:
  • SELECT customer_id FROM sales_data GROUP BY customer_id HAVING COUNT(*) > 1;

Example 1:
Input:
| id | customer_id | sales_amount | sales_date   |
|----|-------------|---------------|---------------|
| 1  | 101         | 200           | 2021-09-01    |
| 2  | 102         | 150           | 2021-09-01    |
| 3  | 101         | 200           | 2021-09-01    |
| 4  | 103         | 300           | 2021-09-02    |

Output:
| customer_id |
|-------------|
| 101         |

Explanation: Customer_id 101 has duplicate entries on 2021-09-01 with the same sales amount of 200.
Example 2:
Input:
| id | customer_id | sales_amount | sales_date   |
|----|-------------|---------------|---------------|
| 5  | 104         | 400           | 2021-09-01    |
| 6  | 104         | 400           | 2021-09-01    |
| 7  | 105         | 150           | 2021-09-02    |

Output:
| customer_id |
|-------------|
| 104         |

Constraints:
  • The table may contain up to 1,000,000 records.

  • customer_id is a positive integer.

  • sales_amount is a monetary value that can be decimal.

  • sales_date is in YYYY-MM-DD format.

Related Snowflake Software Engineer interview prep

Start practicing Snowflake questions

Sign up for free to access walkthroughs, AI-generated questions, and more.

Get Started Free