Snowflake Coding Interview Questions
100 Snowflake coding interview problems with full optimal solutions — 30 easy, 50 medium, 20 hard. Every problem ships with multiple approaches (brute-force first, then the optimal), complexity tables for each, company-specific tips on what an Snowflake interviewer values, and a FAQ section.
- #1easyfrequently asked
1. Two Sum
Given an array of integers and a target sum, return the indices of the two numbers that add up to target. Snowflake asks this as a warm-up to test if you can move from O(n^2) lookups to a hash-map index — the same mental jump a query planner makes when it picks a hash join over a nested-loop join.
- #2easyfrequently asked
2. Valid Parentheses
Determine whether a string of brackets is balanced. Snowflake uses this to test whether you can build a parser-like stack walk — the same primitive used to validate SQL parenthesization in their query parser.
- #3easyfrequently asked
3. Merge Two Sorted Lists
Merge two sorted linked lists into one sorted list. Snowflake asks this because it's the core primitive in a sort-merge join — and they want to see whether you handle the dummy-head pattern cleanly.
- #4easyfrequently asked
4. Remove Duplicates from Sorted Array
In-place deduplicate a sorted array, returning the new length. Snowflake asks this to test two-pointer mechanics and to set up a follow-up on dictionary-encoded columnar deduplication.
- #5easysometimes asked
5. Remove Element
Remove all instances of a target value from an array in-place. Snowflake uses this to test whether you can write a tight scan loop — the same shape as a predicate pushdown filter over a column chunk.
- #6easyfrequently asked
6. Search Insert Position
Given a sorted array and a target, return the index where the target is or where it would be inserted. Snowflake asks this to test binary-search mechanics — the same primitive used to locate a row by clustering key inside a micro-partition's min/max metadata.
- #7easysometimes asked
7. Plus One
Given a big integer represented as a digit array, add one. Snowflake uses this to test edge-case rigor — the carry propagation is the same shape as overflow handling in their NUMBER(38,0) arithmetic kernels.
- #8easyfrequently asked
8. Merge Sorted Array
Merge nums2 into nums1 in-place, both sorted, with nums1 sized to hold both. Snowflake asks this because it's the canonical 'merge in place from the back' trick — and the same trick used in external sort-merge runs.
- #9easysometimes asked
9. Binary Tree Inorder Traversal
Return the in-order traversal of a binary tree. Snowflake asks this to test whether you can produce both the recursive and the iterative-with-stack solution — relevant because their B-tree-style indexes use ordered iteration for range scans.
- #10easysometimes asked
10. Same Tree
Determine whether two binary trees are structurally identical and have the same values. Snowflake asks this as a recursion warm-up before deeper tree problems, often paired with a structural-equality follow-up on query plans.
- #11easysometimes asked
11. Symmetric Tree
Determine whether a binary tree is a mirror of itself around its center. Snowflake asks this to test paired-pointer recursion — the same pattern used to check tree balance invariants in their on-disk index structures.
- #12easyfrequently asked
12. Maximum Depth of Binary Tree
Find the depth of a binary tree. Snowflake uses this as a recursion warm-up and to set up a follow-up on B-tree fanout — the same calculation determines how many index levels a query traverses.
- #13easysometimes asked
13. Balanced Binary Tree
Decide whether a binary tree is height-balanced (every subtree's left/right heights differ by at most 1). Snowflake asks this to test whether you can fuse the 'check' and 'measure' passes into one — the same fusing the query planner does to avoid re-scanning data.
- #14easysometimes asked
14. Path Sum
Determine whether a root-to-leaf path sums to a target. Snowflake asks this to test recursion with a target accumulator — relevant for plan-cost rollup where each operator adds cost on the way up.
- #15easysometimes asked
15. Pascal's Triangle
Generate the first numRows of Pascal's triangle. Snowflake uses this to test row-at-a-time DP building — the same shape as windowing operations over a column where the next row depends on the previous one.
- #16easyfrequently asked
16. Best Time to Buy and Sell Stock
Find the max profit from one buy and one sell. Snowflake asks this to test single-pass min-tracking — the same one-pass min/max aggregation used to build column-chunk statistics during data ingestion.
- #17easysometimes asked
17. Valid Palindrome
Determine whether a string is a palindrome considering only alphanumeric characters. Snowflake uses this to test two-pointer hygiene and Unicode-aware normalization — the same normalization pipeline that runs before COLLATE comparisons in their SQL engine.
- #18easyfrequently asked
18. Single Number
Find the one number in an array where every other appears twice. Snowflake asks this because the XOR trick is exactly the same primitive used to construct erasure-coded data: cheap, commutative, parallel-friendly.
- #19easysometimes asked
19. Linked List Cycle
Determine whether a linked list has a cycle using O(1) space. Snowflake asks this because Floyd's tortoise-and-hare is a textbook example of how to convert from O(n) to O(1) auxiliary space — a recurring theme in their constant-memory streaming kernels.
- #20easyfrequently asked
20. Min Stack
Design a stack that supports push, pop, top, and getMin in O(1) time. Snowflake asks this to test whether you can co-locate state with operations — the same design principle behind their per-column aggregate accumulators.
- #21easysometimes asked
21. Two Sum II - Input Array Is Sorted
Two-sum when input is already sorted, asking for the two indices. Snowflake uses this to test whether you exploit the sortedness — the same instinct a query planner uses to pick a merge-join over a hash-join when inputs are already sorted.
- #22easysometimes asked
22. Majority Element
Find the element appearing more than n/2 times. Snowflake asks this because Boyer-Moore voting is the canonical O(1)-space streaming algorithm — and similar sketch-based algorithms underpin their approximate aggregation functions.
- #23easysometimes asked
23. Rotate Array
Rotate an array to the right by k steps in-place. Snowflake asks this to test the reverse-three-times trick — an elegant O(1) space transformation that mirrors how their executor performs in-place reorderings on column chunks.
- #24easyrarely asked
24. Reverse Bits
Reverse the bits of a 32-bit unsigned integer. Snowflake asks this to test bit-manipulation fluency — relevant for compact column encodings where they sometimes pack rotated/reversed bits to align with vectorized SIMD masks.
- #25easysometimes asked
25. Number of 1 Bits
Count the number of 1 bits in an integer (popcount). Snowflake uses this to test bit-manipulation knowledge and to set up a follow-up on bitmap-index intersection — popcount is the hot loop in bitmap predicate evaluation.
- #26easysometimes asked
26. House Robber
Maximize loot from non-adjacent houses. Snowflake asks this as a 1D-DP warm-up before harder DP problems; the rolling-two-variable variant is also a model for incremental aggregation state.
- #27easyrarely asked
27. Happy Number
Determine whether repeatedly summing the squares of a number's digits eventually reaches 1. Snowflake uses this to test cycle detection in a function-iteration setting — relevant for recursive CTE termination analysis.
- #28easysometimes asked
28. Isomorphic Strings
Decide whether two strings are isomorphic — there's a one-to-one mapping between characters. Snowflake asks this to test bijection logic — the same shape used to validate schema-to-schema column mappings during data sharing.
- #29easyfrequently asked
29. Reverse Linked List
Reverse a singly linked list. Snowflake asks this as a pointer-manipulation warm-up and to verify that you can handle the three-pointer dance — the same kind of bookkeeping required when reversing scan direction inside their executor.
- #30easyfrequently asked
30. Contains Duplicate
Decide whether an array contains any duplicate value. Snowflake uses this to test the dedup primitive — and to lead into discussions of approximate-cardinality structures like HyperLogLog, which they use for APPROX_COUNT_DISTINCT.
- #31mediumfrequently asked
31. Add Two Numbers
Add two non-negative integers stored as linked lists in reverse-digit order. Snowflake asks this to test carry propagation logic — the same arithmetic kernel that underlies their high-precision NUMBER type's addition.
- #32mediumfrequently asked
32. Longest Substring Without Repeating Characters
Find the length of the longest substring with all distinct characters. Snowflake uses this to test sliding-window mastery — the same technique their executor uses for running-distinct window functions.
- #33mediumsometimes asked
33. Longest Palindromic Substring
Find the longest palindromic substring of a string. Snowflake asks this to test the 'expand-around-center' insight — and how to avoid the O(n^2) memory cost of DP when streaming through a column would be cheaper.
- #34mediumsometimes asked
34. Container With Most Water
Find two lines forming the largest container of water. Snowflake uses this to test whether you can argue the correctness of the two-pointer move — the same kind of monotonic reasoning that justifies join-order pruning in their planner.
- #35mediumfrequently asked
35. 3Sum
Find all unique triplets that sum to zero. Snowflake uses this to test deduplication discipline at multiple levels — the same care needed when implementing DISTINCT inside GROUP BY queries on multiple columns.
- #36mediumsometimes asked
36. Letter Combinations of a Phone Number
Generate all letter combinations from a phone-keypad digit string. Snowflake asks this to test cartesian-product generation — the same enumeration shape that underlies their CROSS JOIN and LATERAL FLATTEN execution.
- #37mediumsometimes asked
37. Remove Nth Node From End of List
Remove the n-th node from the end of a linked list in one pass. Snowflake asks this to test the two-pointer-with-gap technique — the same approach used to maintain windowed iterators over streaming row sets.
- #38mediumsometimes asked
38. Generate Parentheses
Generate all valid parenthesizations of n pairs. Snowflake uses this to test pruning during backtracking — the same instinct a query planner uses to cut off candidate-plan generation when constraints prove a partial plan can't extend to a valid full plan.
- #39mediumrarely asked
39. Swap Nodes in Pairs
Swap every two adjacent nodes in a linked list. Snowflake asks this to test pointer-manipulation precision — the same precision required when reordering rows in their pipelined executor.
- #40mediumsometimes asked
40. Next Permutation
Rearrange numbers to the lexicographically next greater permutation in place. Snowflake asks this to test whether you can articulate the three-step swap-and-reverse algorithm — a precise, in-place transformation similar to executor-side row reorderings.
- #41mediumfrequently asked
41. Search in Rotated Sorted Array
Search for a target in a sorted array that has been rotated at an unknown pivot. Snowflake asks this to test modified binary search reasoning — the same instinct used when indexing data that may be partially ordered due to micro-partition layout.
- #42mediumfrequently asked
42. Find First and Last Position of Element in Sorted Array
Find the first and last index of a target in a sorted array. Snowflake asks this to test lower_bound/upper_bound mechanics — the same primitive used to extract row ranges for a clustered-column predicate inside a micro-partition.
- #43mediumsometimes asked
43. Valid Sudoku
Determine whether a partially-filled 9x9 Sudoku board is valid. Snowflake uses this to test multi-key uniqueness checking — the same pattern used to enforce composite unique constraints in their schema validation.
- #44mediumsometimes asked
44. Combination Sum
Find all unique combinations of candidates summing to target, with reuse allowed. Snowflake asks this to test backtracking + the 'start index' trick to avoid duplicate combinations — the same technique used to enumerate physical plans without revisiting equivalent shapes.
- #45mediumrarely asked
45. Combination Sum II
Find all unique combinations summing to target where each number can be used once, given an input that may contain duplicates. Snowflake asks this to test the sort-then-skip-equal pattern for dedup — same trick they use for DISTINCT over duplicate-laden columns.
- #46mediumsometimes asked
46. Multiply Strings
Multiply two non-negative integers represented as strings, without converting to integer types directly. Snowflake uses this as the canonical fixed-point multiplication exercise — directly relevant to NUMBER(p,s) arithmetic kernels.
- #47mediumfrequently asked
47. Permutations
Generate all permutations of a distinct-integer array. Snowflake asks this to test backtracking with a used-mask — relevant for join-order enumeration where the planner permutes table orderings to find the optimal plan.
- #48mediumsometimes asked
48. Rotate Image
Rotate an n x n 2D matrix 90 degrees clockwise in place. Snowflake asks this to test in-place matrix transformation — directly relevant to transpose-and-swap operations on column chunks during their executor's data shuffling.
- #49mediumfrequently asked
49. Group Anagrams
Group strings that are anagrams of each other. Snowflake asks this to test composite-key grouping — the same hashing pattern used in GROUP BY execution where you bucket rows by a normalized key.
- #50mediumrarely asked
50. Spiral Matrix
Traverse an m x n matrix in spiral order. Snowflake asks this to test boundary tracking — relevant for windowing operations over multi-dimensional storage layouts.
- #51mediumsometimes asked
51. Jump Game
Decide whether you can reach the last index. Snowflake asks this to test greedy reasoning — the same shape as deciding whether a partial plan can still be completed within a cost budget.
- #52mediumfrequently asked
52. Merge Intervals
Merge overlapping intervals. Snowflake asks this to test sort-then-sweep — the same primitive used to coalesce overlapping micro-partition ranges during clustering maintenance.
- #53mediumsometimes asked
53. Unique Paths
Count unique paths from top-left to bottom-right in an m x n grid moving only right or down. Snowflake asks this as a 2D-DP warm-up and to set up a follow-up on space optimization with rolling rows.
- #54mediumsometimes asked
54. Minimum Path Sum
Find the minimum-sum path from top-left to bottom-right of a grid. Snowflake uses this to test 2D-DP with state compression — the same shape they apply when computing min-cost plans over an operator DAG.
- #55mediumsometimes asked
55. Simplify Path
Simplify a Unix-style absolute path. Snowflake uses this to test stack-based parsing — relevant to their SQL parser's path resolution for staged file references like @stage/path/to/file.csv.
- #56mediumsometimes asked
56. Edit Distance
Compute the minimum edit distance between two strings (insert/delete/replace). Snowflake asks this because it's the canonical 2D-DP — and because their fuzzy-match (Jaro-Winkler, Levenshtein) UDF is built on the same recurrence.
- #57mediumsometimes asked
57. Set Matrix Zeroes
If an element is 0, set its entire row and column to 0, in place. Snowflake asks this to test in-place state propagation using existing storage as flags — same idea as encoding null bitmaps inline with column data.
- #58mediumsometimes asked
58. Search a 2D Matrix
Search a target in a matrix sorted row-major. Snowflake asks this to test 1D-as-2D binary search — same insight when treating a multi-block column store as a flat sorted sequence for predicate evaluation.
- #59mediumsometimes asked
59. Sort Colors
Sort an array of three values (0, 1, 2) in one pass. Snowflake asks this for the Dutch-National-Flag three-pointer technique — directly relevant to in-place partitioning during their executor's range repartition.
- #60hardfrequently asked
60. Minimum Window Substring
Find the minimum window in s that contains all characters of t. Snowflake asks this to test sliding-window mastery with multi-character constraints — same shape as streaming join-key matching where you maintain a running multiset.
- #61mediumrarely asked
61. Combinations
Generate all combinations of k numbers from 1..n. Snowflake asks this as a backtracking template — the same enumeration shape as choosing k tables to join (Selinger-style join-order enumeration).
- #62mediumsometimes asked
62. Subsets
Generate all 2^n subsets. Snowflake asks this to test bitmask vs backtracking enumeration — and to set up a discussion of bitmask DP for join-order optimization.
- #63mediumsometimes asked
63. Word Search
Given a 2D board, find whether a word can be constructed by adjacent cells without reusing a cell. Snowflake asks this to test DFS-with-backtrack on a grid — same shape as path-discovery during dependency-graph traversal of materialized views.
- #64mediumrarely asked
64. Remove Duplicates from Sorted Array II
Remove duplicates from a sorted array so each value appears at most twice. Snowflake uses this to test the generalized 'allow k occurrences' pattern — useful for k-NN deduplication during data ingestion.
- #65mediumrarely asked
65. Search in Rotated Sorted Array II
Search in a rotated sorted array with duplicates allowed. Snowflake uses this to highlight how duplicates degrade binary search — the same concern when a clustering key is low-cardinality and pruning effectiveness drops.
- #66mediumrarely asked
66. Remove Duplicates from Sorted List II
Remove all nodes from a sorted linked list that have duplicates, leaving only distinct values. Snowflake asks this to test the dummy-head + look-ahead pattern — same shape as stream-side DISTINCT processing.
- #67mediumrarely asked
67. Partition List
Partition a linked list around a value x so that nodes < x come before nodes >= x, preserving relative order. Snowflake asks this to test two-builder pattern — same shape as range-repartition during shuffle.
- #68mediumsometimes asked
68. Decode Ways
Count the number of ways to decode a digit string into letters (A=1, B=2, ..., Z=26). Snowflake asks this for 1D DP with branching transitions — relevant to ambiguous tokenization during SQL parsing.
- #69mediumrarely asked
69. Reverse Linked List II
Reverse a linked-list sub-range from position left to right, in place. Snowflake asks this to test pointer manipulation under a tight constraint — relevant for batch-flipping micro-partitions during ORDER BY DESC over partial data.
- #70mediumrarely asked
70. Restore IP Addresses
Generate all valid IP-address splits of a digit string. Snowflake asks this to test backtracking with multi-segment constraints — same shape as parsing dotted identifiers like db.schema.table.column.
- #71mediumrarely asked
71. Unique Binary Search Trees II
Generate all structurally unique BSTs storing values 1..n. Snowflake asks this to test recursion-with-memoization and to set up a discussion on plan-tree generation — there are many ways to assemble n joins.
- #72mediumsometimes asked
72. Unique Binary Search Trees
Count the number of structurally unique BSTs storing values 1..n. Snowflake asks this for the Catalan-number DP — directly relevant to counting alternative plan shapes for n-table joins.
- #73mediumfrequently asked
73. Validate Binary Search Tree
Determine whether a tree is a valid BST. Snowflake asks this to test the global-constraint vs local-check distinction — same shape as validating cross-table constraints during schema changes.
- #74mediumsometimes asked
74. Binary Tree Level Order Traversal
BFS a binary tree and group nodes by level. Snowflake asks this to test queue-based BFS — directly relevant to plan-tree topological traversal during cost computation.
- #75mediumrarely asked
75. Binary Tree Zigzag Level Order Traversal
BFS but alternate left-to-right and right-to-left per level. Snowflake asks this to test BFS with a flip — direct analog to alternating-direction aggregation in window functions over partitioned streams.
- #76mediumsometimes asked
76. Construct Binary Tree from Preorder and Inorder Traversal
Rebuild a binary tree from preorder + inorder traversals. Snowflake asks this to test recursive structure recovery and to set up a discussion on plan-tree deserialization.
- #77mediumfrequently asked
77. LRU Cache
Design an LRU cache with O(1) get and put. Snowflake asks this constantly because it's the foundation of their warehouse cache — frequently-accessed micro-partitions stay hot in SSD; cold ones get evicted by exactly this policy.
- #78mediumsometimes asked
78. Word Break
Decide whether a string can be segmented into a sequence of dictionary words. Snowflake asks this for 1D DP with set lookup — relevant to query-rewrite where you match identifier strings against catalog tables.
- #79mediumfrequently asked
79. Coin Change
Find the minimum number of coins that sum to a target. Snowflake asks this as the canonical 1D unbounded-knapsack — relevant to choosing min-cost combinations of cached vs cold partitions.
- #80mediumsometimes asked
80. Longest Increasing Subsequence
Find the length of the longest strictly increasing subsequence. Snowflake asks this to test the O(n log n) patience-sort trick — directly relevant to streaming statistics maintenance over ordered data.
- #81hardsometimes asked
81. Median of Two Sorted Arrays
Find the median of two sorted arrays in O(log(min(m, n))). Snowflake asks this to test binary search on partitions — directly relevant to merging sorted micro-partitions for median computation during APPROX_PERCENTILE follow-up.
- #82hardsometimes asked
82. Regular Expression Matching
Implement regex matching with . and *. Snowflake asks this for 2D DP with branching transitions — directly relevant to their REGEXP_LIKE evaluator and LIKE pattern matching.
- #83hardfrequently asked
83. Merge k Sorted Lists
Merge k sorted linked lists into one. Snowflake asks this because it's the literal primitive for external sort-merge — when a sort spills to disk and yields k sorted runs, merging them is exactly this problem.
- #84hardsometimes asked
84. Reverse Nodes in k-Group
Reverse a linked list in groups of k nodes. Snowflake asks this because batched reversal in groups is precisely how their executor flips row direction in fixed-size batches for ORDER BY DESC over partial micro-partitions.
- #85hardrarely asked
85. Substring with Concatenation of All Words
Find all starting indices where a substring is a concatenation of every word exactly once. Snowflake asks this for multi-key sliding-window mastery — relevant to multi-column join-key matching in streaming joins.
- #86hardrarely asked
86. Longest Valid Parentheses
Find the longest valid parentheses substring. Snowflake asks this for stack-with-index — relevant to recovering nesting depth during SQL parser error reporting.
- #87hardrarely asked
87. Sudoku Solver
Solve a 9x9 Sudoku puzzle. Snowflake asks this to test backtracking with constraint propagation — relevant to constraint solving during type inference and constraint validation.
- #88hardsometimes asked
88. First Missing Positive
Find the smallest missing positive integer in O(n) time and O(1) space. Snowflake asks this for the cyclic-placement trick — relevant to building dense column-id mappings during data ingestion.
- #89hardsometimes asked
89. Trapping Rain Water
Compute the volume of water trapped between bars after rain. Snowflake asks this for the two-pointer trick — relevant to computing memory-bound estimation in their planner where left and right side constraints both matter.
- #90hardfrequently asked
90. Wildcard Matching
Implement wildcard pattern matching with ? and *. Snowflake asks this because LIKE patterns in their SQL engine are exactly this matching — % maps to *, _ maps to ?, and the engine must compile patterns efficiently.
- #91mediumsometimes asked
91. Jump Game II
Find the minimum number of jumps to reach the last index. Snowflake asks this for BFS-style greedy with level boundaries — relevant to estimating the minimum number of repartition steps in distributed plan execution.
- #92hardrarely asked
92. N-Queens
Place n queens on an n x n chessboard so none attack each other. Snowflake asks this as the canonical backtracking-with-constraint-bitmask — relevant to constraint solving during query rewrite where multiple non-conflicting predicates must be selected.
- #93hardrarely asked
93. N-Queens II
Count the number of distinct n-queens solutions. Snowflake asks this for pure constraint counting — directly relevant to counting valid plan configurations during planner exploration.
- #94hardsometimes asked
94. Insert Interval
Insert a new interval into a sorted list of non-overlapping intervals, merging where needed. Snowflake asks this for streaming-friendly interval management — relevant to incremental micro-partition coalescing during continuous ingestion.
- #95hardrarely asked
95. Valid Number
Determine whether a string is a valid number (integer, decimal, or scientific notation). Snowflake asks this because their SQL parser must tokenize numeric literals correctly — and the spec is full of edge cases.
- #96hardrarely asked
96. Text Justification
Justify text to a fixed width, distributing spaces evenly. Snowflake asks this to test careful greedy packing with edge-case spacing — relevant to formatted CSV unload and result-set pretty-printing.
- #97hardsometimes asked
97. Largest Rectangle in Histogram
Find the largest rectangle area in a histogram. Snowflake asks this for the monotonic-stack pattern — directly relevant to range-max queries during query optimization.
- #98hardrarely asked
98. Maximal Rectangle
Find the largest rectangle of 1s in a binary matrix. Snowflake asks this as the 2D extension of Largest-Rectangle-in-Histogram — relevant to range-max queries over rectangular data tiles.
- #99hardrarely asked
99. Scramble String
Determine whether one string can be obtained by recursively partitioning another. Snowflake asks this for recursive partitioning with memoization — same recursion shape as proving plan equivalence under reordering.
- #100hardfrequently asked
100. Serialize and Deserialize Binary Tree
Convert a binary tree to and from a string. Snowflake asks this as the canonical tree-serialization problem — directly relevant to how their distributed scheduler ships compiled query plans across compute nodes.