Data Science Coding Interview Problems: 15 That Actually Appear

- Data science coding interview problems are easier than SWE loops: easy and medium LeetCode, with occasional hard at Google and Databricks
- Hash maps replace nested loops for Two Sum, Group Anagrams, and Subarray Sum — the same logic as SQL
GROUP BY - Sliding window (Longest Substring, Minimum Window) is the algorithmic version of a rolling average over time-series data
- Two-heap design maintains a running median as numbers stream in, the most explicitly statistical problem in the list
- Merge Intervals and Non-overlapping Intervals map directly to experiment scheduling and overlapping A/B test window analysis
- Python stdlib —
Counter,heapq,defaultdict— is expected; interviewers assume you reach for it naturally - Coin Change and Number of Islands are the minimum DP and graph problems worth knowing cold before any DS loop
Nobody warns you. You spend years learning pandas, statsmodels, and sklearn. You can wrangle a 10GB CSV and build a regression pipeline before lunch. Then a recruiter schedules you for a "technical screen" and suddenly you're staring at a blank editor with no NumPy, no autocomplete, and a Two Sum problem.
Data science coding interviews are not software engineering interviews with a statistics coating. The DSA slice is lighter, the SQL slice is heavier, and the problems that actually appear have a real data flavor. Two Sum shows up. Segment trees don't.
Below are the 15 problems that appear most often across Google DS, Meta DS, Amazon DS, Databricks, and similar roles, organized by pattern. Master these and you've covered roughly 80% of the DSA coding you'll encounter in a data science loop. For a broader overview of what the full loop looks like, see DSA for Data Scientists: What Your Coding Interview Actually Tests.
The Part Where They Explain You Can't Use Pandas
A few differences worth knowing before we get into the problems:
- The bar is easy and medium problems, with occasional hard excursions at Google and Databricks. Meta and most mid-stage startups stay squarely at LeetCode medium. Nobody expects a suffix array.
- Python is the default.
collections.Counter,heapq, anddefaultdictare fair game. - Problems skew toward data-analysis shapes: frequency counting, running statistics, time-series intervals.
- Some companies (Meta, Airbnb) run lighter DSA rounds because SQL rounds absorb more of the technical signal.
- If the job description says "applied scientist" or "ML engineer," the bar creeps toward SWE territory. Budget extra weeks.
Now, the problems.
SQL's GROUP BY Is Just a Hash Map
Most data science work is counting things, grouping things, and looking things up. These three problems cover that entire family. The interviewer just calls it a hash map.
1. Two Sum (LC 1, Easy)
Every DS interview either asks this directly or asks a variant. The hash map solution drops the O(n²) brute force to O(n) by storing each value and checking for its complement in one pass.
It's also a calibration problem. Reach for the nested loop and the interviewer flags it immediately. You have maybe 30 seconds before their face changes.
def twoSum(nums: list[int], target: int) -> list[int]: seen = {} for i, n in enumerate(nums): if target - n in seen: return [seen[target - n], i] seen[n] = i return []
2. Group Anagrams (LC 49, Medium)
Group strings that are anagrams of each other. This is GROUP BY with a computed key. Sort each string and use that as a dictionary key. Strings that are anagrams share the same sorted form.
The insight: a sorted string is the canonical form of all its anagrams. The same idea, grouping by a computed signature, shows up in feature hashing and duplicate detection.
3. Subarray Sum Equals K (LC 560, Medium)
Count subarrays whose elements sum to exactly k. Brute force is O(n²). The fix: sum(i..j) = prefix[j] - prefix[i-1], so keeping a running dictionary of prefix sums gives you O(n) in one pass.
This is a time-series problem in a trench coat. "How many windows of my data sum to a target value" is a real question in sales and traffic analysis. See Prefix Sum Problems Leave the Same Clues for the full pattern.
Rolling Average Without a DataFrame
A sliding window maintains a contiguous subset of your data as you scan. It's the algorithmic version of a rolling average, and the template is always the same: expand right, shrink left when a condition breaks.
4. Longest Substring Without Repeating Characters (LC 3, Medium)
Find the longest substring with all unique characters. Expand the right pointer, shrink the left when a duplicate enters the window. One pass, O(n), with a set tracking current window contents.
This establishes the variable-width window template. Every other sliding window problem is a variation on it.
5. Minimum Window Substring (LC 76, Hard)
Find the smallest substring of s containing all characters of t. Same template as LC 3, but the shrink condition becomes "window contains all required characters."
This is the hardest sliding window problem you're likely to see in a DS loop. Google and Databricks go here. Most companies stop at LC 3 and declare victory.
The Data Structure That Actually Thinks Like a Data Scientist
Heaps power top-K queries, percentile calculations, and streaming statistics. Every problem in this section has a direct analogy to daily DS work. Your interviewer chose these on purpose.
6. Top K Frequent Elements (LC 347, Medium)
Return the k most frequent elements. Count frequencies, then maintain a min-heap of size k. Push each element, pop when the heap exceeds k. The O(n log k) approach beats O(n log n) full sort when k << n.
This is literally "give me the top 10 most common values" in Python. The kind of thing you'd normally do in one line of pandas. They want to see you rebuild it from scratch.
import heapq from collections import Counter def topKFrequent(nums: list[int], k: int) -> list[int]: counts = Counter(nums) return heapq.nlargest(k, counts.keys(), key=counts.get)
7. Kth Largest Element in an Array (LC 215, Medium)
Find the kth largest value without full sorting. Two options: min-heap of size k at O(n log k), or quickselect at O(n) average. Know both and be ready to explain the tradeoff. Interviewers at Google and Amazon will ask which you'd choose for a streaming dataset versus a static array.
8. Find Median from Data Stream (LC 295, Hard)
Maintain the running median as numbers arrive. Two heaps: a max-heap for the lower half, a min-heap for the upper half. Keep them balanced within one element; the median is the top of one heap or the average of both tops.
This is the most explicitly statistical problem in the list. It shows up at Google, Databricks, and quant-adjacent DS roles. The two-heap design is not obvious under pressure, so practice it cold. See Top-K Heap Pattern for the full toolkit.
They Took Your NumPy. Sorry.
Data scientists live in NumPy. These problems test whether you can reason about array structure without reaching for a library. The good news: you can. The bad news: you have to.
9. Maximum Subarray (LC 53, Easy)
Find the contiguous subarray with the largest sum. Kadane's algorithm: at each element, choose between extending the current subarray or starting fresh. Initialize to nums[0], not 0, or you'll fail on all-negative arrays. That edge case silently bites people who learned this from a blog post that got it wrong.
def maxSubArray(nums: list[int]) -> int: best = current = nums[0] for n in nums[1:]: current = max(n, current + n) best = max(best, current) return best
"What's the best consecutive period for this metric" is a real business question. This is signal detection in time series. Just without the nice API.
10. Product of Array Except Self (LC 238, Medium)
Return an array where output[i] is the product of every element except nums[i], without division, in O(n). Build prefix products left-to-right, then a suffix-product pass right-to-left, combining in place.
The constraint "no division" forces the prefix-suffix insight. NumPy makes this trivial (np.prod(nums) / nums[i]), which is exactly why interviewers ban it. The division approach also silently breaks on zeros.
11. Rotate Image (LC 48, Medium)
Rotate an n×n matrix 90 degrees clockwise in place. Transpose (swap [i][j] with [j][i]), then reverse each row. O(n²) time, O(1) extra space, which beats np.rot90's allocation.
Matrix rotation appears in image preprocessing and feature map transformations. If the role touches computer vision, expect this.
When the Interviewer Starts Talking About "Temporal Data"
Events with start and end timestamps. Experiment windows. Overlapping range queries. This pattern comes up more often than most DS candidates expect, probably because it maps directly to real data work they already do.
12. Merge Intervals (LC 56, Medium)
Merge all overlapping intervals. Sort by start time, then scan: if the current interval overlaps with the last merged one, extend its end. Otherwise start a new entry.
The subtle bug: use max() when extending the end, not direct assignment. A contained interval [1,10] followed by [2,5] would incorrectly shrink the end to 5 without it. See Merge Intervals: The Template Behind Every Scheduling Problem.
13. Non-overlapping Intervals (LC 435, Medium)
Find the minimum number of intervals to remove so the rest don't overlap. Sort by end time (not start time), then greedily keep intervals that don't conflict with the last kept one.
This maps directly to experiment scheduling. "Given these A/B test windows, what's the minimum number to drop so no two overlap?" Very practical framing for DS roles. The interviewer is basically asking you to optimize a calendar.
One DP Problem. That's All They Want.
DS interviews rarely go deep on dynamic programming. You won't need interval DP or bitmask DP. But you need to demonstrate you understand what DP actually is. One problem, done clearly, is enough.
14. Coin Change (LC 322, Medium)
Find the minimum number of coins that sum to a target amount. Build a table dp[0..amount] where dp[i] = minimum coins to make amount i. For each coin, update dp[i] = min(dp[i], dp[i - coin] + 1).
Knowing this cold lets you walk any interviewer through the structure of bottom-up DP in under two minutes. One problem done well signals the whole pattern family. You don't need to know twenty DP problems. You need to explain one clearly.
The Graph Problem at the End of the Dungeon
Graphs appear more in ML-adjacent roles: recommendation systems, graph neural networks, pipeline dependency resolution. For most DS interviews, one graph problem is the ceiling. And it's almost always this one.
15. Number of Islands (LC 200, Medium)
Count connected groups of '1's in a 2D grid. BFS or DFS from each unvisited land cell, marking cells visited as you go.
Connected components in a grid is the algorithmic equivalent of clustering. The outer loop over all cells is mandatory for disconnected regions. Miss it and you count only one island regardless of how many the grid contains. This error happens in about half of first attempts, including second attempts under pressure.
Practice Like a Data Scientist, Not a SWE
Use Python. collections.Counter, heapq, and defaultdict are all expected.
Know the SQL analog for each pattern. Hash maps are GROUP BY. Merge intervals is session analysis. Top-K is ORDER BY ... LIMIT k. Connecting the algorithmic pattern to the real DS operation makes solutions easier to remember and explanations easier to give. You already think this way. Let it show.
Practice complexity explanations out loud. "O(n log k) for the heap solution because..." Interviewers hear that and mark a box. SpaceComplexity's voice-based mock interviews score exactly that kind of verbal reasoning, with rubric-based feedback on whether your explanation actually landed.