Snowflake software engineer interviews cover algorithms, data structures, system design, and coding problems drawn from real interview rounds.
Question A message-processing pipeline consists of n services that must all be traversed in sequence. The pipeline's effective throughput is...
k representing the maximum number of allowed color changes,...Input: Arrays, count the number of contiguous substrings that: 1. Consist entirely of vowel characters ('a', 'e', 'i', 'o', 'u') 2....Input: StringAPIThrottleManager for an API gateway that enforces multiple rate-limiting policies simultaneously. Each policy defines a sliding window...Input: Integer(s)"red", "blue", or "" (empty). A...Input: 2D gridn departments (numbered 0 to n-1). Departments can inherit access rights from...Input: ListProductSalesRanker class for an e-commerce platform that tracks cumulative product sales and returns the top-ranked products on demand....Input: ListResizableLRUCache 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)TaggedValueStore for a configuration system that stores string keys mapped to integer values. The store supports standard CRUD operations...Input: ListScenario
Part 1 — Warehouse guardrails
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.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.(account, warehouse), not by warehouse name alone.WAREHOUSE_BURST: alert if the current warehouse has more than 3 queries in the last 60 seconds.WAREHOUSE_CREDITS: alert if the current warehouse has more than 10.00 estimated credits in the last 300 seconds.{ "query_id": ..., "alerts": [rule_id, ...] }.def evaluate_queries(records: list[dict[str, str]]):
Example 1:
{
"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"}
]
}[
{"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"]}
]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
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.rule_id. Each alert now includes rule_id, scope, observed, and limit. Serialize counts as integer strings and credits with exactly two fractional digits.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.def evaluate_with_policies(
records: list[dict[str, str]],
policies: list[dict[str, str]]
):Example 2:
{
"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"}
]
}[
{"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"}
]}
]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:
{
"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"}
]
}[
{"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"}
]}
]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:
level-order, where each level is processed from left to right.def level_order_traversal(root: Optional[TreeNode]) -> List[List[int]]:root = [3,9,20,null,null,15,7] [[3],[9,20],[15,7]] root = [1] [[1]] 1000 nodes. [-1000, 1000].(course_a, course_b) meaning course_b is dependent on course_a.def course_order(dependencies: List[Tuple[str, str]]) -> List[str]:[('CS101', 'CS102'), ('CS102', 'CS103'), ('CS101', 'CS104')]['CS101', 'CS102', 'CS103', 'CS104'][('CS101', 'CS102'), ('CS102', 'CS101')][]10^4.10^4.(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.def can_finish(num_courses: int, prerequisites: List[Tuple[int, int]]) -> boolnum_courses = 2, prerequisites = [(1, 0)] True num_courses = 2, prerequisites = [(1, 0), (0, 1)] False 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].true if all courses can be finished, and false if there's a cycle.def can_finish(num_courses: int, prerequisites: List[List[int]]) -> bool:num_courses = 2, prerequisites = [[1, 0]]Truenum_courses = 2, prerequisites = [[1, 0], [0, 1]]False1 <= num_courses <= 20000 <= prerequisites.length <= 5000prerequisites[i].length == 2 0 <= prerequisites[i][0], prerequisites[i][1] < num_courses[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.def can_complete_courses(num_courses: int, prerequisites: List[List[int]]) -> bool:num_courses = 2, prerequisites = [[0, 1]] True 1 and then course 0.num_courses = 2, prerequisites = [[0, 1], [1, 0]] False 0 and course 1.1 <= num_courses <= 2000 0 <= prerequisites.length <= 5000 prerequisites[i].length == 2 [0, num_courses - 1].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.SELECT customer_id FROM sales_data GROUP BY customer_id HAVING COUNT(*) > 1;| 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 |
| customer_id | |-------------| | 101 |
101 has duplicate entries on 2021-09-01 with the same sales amount of 200.| 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 |
| customer_id | |-------------| | 104 |
customer_id is a positive integer. sales_amount is a monetary value that can be decimal. sales_date is in YYYY-MM-DD format.Sign up for free to access walkthroughs, AI-generated questions, and more.
Get Started Free