Top 15 Microsoft Coding Interview Problems: Patterns and What Each Teaches

June 6, 202610 min read
interview-prepcareerdsaalgorithms
Top 15 Microsoft Coding Interview Problems: Patterns and What Each Teaches
TL;DR
  • Two Sum is Microsoft's most common opening problem; have follow-up answers for the sorted-array, all-pairs, and negative-value variants ready
  • Tree problems (BFS, construction, diameter) dominate Microsoft loops more than at most other major tech companies
  • Design problems (Min Stack, LRU Cache) appear in every loop; know the O(1) implementation and why a doubly linked list is required before they ask
  • The sliding window max(left, last_seen[char] + 1) bug is the single most common submission error on the most-asked problem
  • Kadane's algorithm must initialize to nums[0], not 0, or it silently breaks on all-negative arrays
  • Microsoft scores communication alongside correctness: narrating your approach for the first two minutes before coding separates SDE from SDE2 candidates on borderline calls

You walk into a Microsoft coding round expecting a warm-up Two Sum, maybe a linked list problem, and a collegial chat about Big-O. Then they ask you to construct a binary tree from two separate traversals, design an LRU cache from scratch, and explain the complexity of your Kadane's implementation without prompting. Welcome.

Microsoft's coding rounds are heavier on trees and design than most engineers expect. Every round expects a working solution, a complexity analysis without prompting, and at least one follow-up handled cleanly. That last part is where most candidates lose points.

These are the 15 Microsoft coding interview problems that appear most often in recent interview reports, the pattern each represents, and the specific thing interviewers are watching for. Ordered by frequency.

The 15 Problems, at a Glance

#ProblemDifficultyPattern
1Two SumEasyHash Map
2Group AnagramsMediumHash Map + Canonical Key
3Longest Substring Without Repeating CharactersMediumSliding Window
4Best Time to Buy and Sell StockEasyArray / One-Pass
5Maximum SubarrayMediumKadane's
6Merge IntervalsMediumSort + Sweep
7Reverse Linked ListEasyLinked List
8Min StackMediumStack Design
9Binary Tree Level Order TraversalMediumBFS
10Construct Binary Tree from Preorder and InorderMediumTrees + Recursion
11Diameter of Binary TreeEasyDFS + Post-order
12Clone GraphMediumGraph BFS/DFS
13Word SearchMediumBacktracking
14LRU CacheMediumDesign (HashMap + DLL)
15Word BreakMediumDP / Hash Set

Microsoft's LeetCode tag skews roughly 37% Easy, 50% Medium, 13% Hard. Trees and design problems appear more than at most other companies. A candidate who can solve all 15 cold is in strong shape for a phone screen. Someone who can articulate the tradeoffs between approaches is in shape for SDE2.

Hash Map: The Answer to at Least Half Your Problems

Two Sum is the most common opening problem in Microsoft coding rounds. The easy version tests whether you reach O(n) with a single-pass hash map. The real test is the follow-up: what if the array is sorted? What if you need all pairs? What if values can be negative? Have answers ready.

Group Anagrams (#49) sits one level up. You need to recognize that sorted characters form a canonical key, then build a map from key to list. A hash map converts an O(n²) nested loop into O(n) by shifting comparison cost to constant-time lookups. Once that instinct is locked in, you'll reach for it correctly on problems that don't announce themselves as hash map problems.

The bug that kills candidates on Group Anagrams: using a mutable list as a dict key in Python. Runtime error. Sort the string, use that as the key. The compiler is not being personal. It is being correct.

This Sliding Window Bug Passes Some Tests. That's the Worst Kind.

Longest Substring Without Repeating Characters (#3) shows up in nearly every curated Microsoft list. The naive approach is O(n²). The correct approach maintains a window with a character-to-last-index map and shrinks from the left when a repeat is found.

The bug: candidates write left = last_seen[char] + 1 instead of left = max(left, last_seen[char] + 1). Without the max, you can move the window left when a repeat was already outside the window. The output may still pass some test cases, which makes it one of those bugs that fails half the tests and leaves candidates convinced the problem is somewhere else entirely. It is not somewhere else.

Tom the cat swinging a frying pan at Jerry, labeled "Me debugging" vs "The bug"

The bug is right there. It has always been right there.

See Sliding Window Bugs That Pass Tests and Fail Interviews for the full pattern.

Microsoft Really, Really Loves Trees

Microsoft asks more tree problems per loop than almost any other major tech company. It is not a phase. Three problems cover the space.

Binary Tree Level Order Traversal (#102) is the BFS entry point. It looks simple until you realize the return type is a list of lists, not a flat list. The idiomatic solution snapshots the queue length at the start of each level: for i in range(len(queue)). Without this, you get all nodes in one flat list. Wrong output, delivered with full confidence.

Construct Binary Tree from Preorder and Inorder (#105) separates candidates who understand trees from candidates who have memorized traversals. The first element of preorder is always the root. Its position in the inorder array defines the left and right subtree sizes. Build a hash map from value to inorder index before starting recursion. Without it, you're searching linearly at each level and the solution is O(n²). Interviewers at SDE2 level will ask.

Diameter of Binary Tree (#543) trips people because the longest path may not pass through the root. Post-order DFS returns subtree height to the caller and updates a nonlocal max-diameter as a side effect. Do not return diameter up the chain. Return height. That error shows up in the majority of wrong attempts, and Microsoft interviewers have seen it so many times they could spot it from across a parking lot.

For the full catalog of tree bugs, see Binary Trees Aren't Hard. These Six Bugs Are..

The Design Problems Are the Boss Fights

Microsoft consistently includes at least one design problem per loop. The two that appear most are Min Stack and LRU Cache.

Min Stack (#155) requires push, pop, top, and getMin all in O(1). The key is a parallel min-stack that records the current minimum at every push. When you pop the main stack, pop the min-stack too. Candidates who try to maintain a single min variable fail when that minimum gets removed. The stack forgets, and so does your score.

LRU Cache (#146) is the harder ask, and it is a genuine design problem. You need a hash map for O(1) key lookup and a doubly linked list for O(1) order tracking. The standard implementation uses two sentinel nodes (head and tail) so insertion and removal never require null checks. Once it works, expect the follow-up: why a doubly linked list? Why not singly? The answer is that deleting a node in O(1) requires the previous pointer. Know it before they ask.

Clone Graph and Word Search: One Trap, Two Costumes

Clone Graph (#133) tests deep-copy on a cyclic graph. The fix is a hash map from original node to its clone. If you've already cloned a node, return the clone. If you haven't, create it, add it to the map, then clone its neighbors. Without the map, any cycle causes infinite recursion. You have built a very elegant program that runs forever.

Word Search (#79) is the backtracking problem Microsoft returns to most. You traverse a 2D grid character by character, marking cells visited before recursion and unmarking them after. Forgetting to restore the cell after backtracking corrupts the grid for sibling branches. That undo step is what makes this backtracking rather than plain DFS. The grid is not a crime scene. Put it back the way you found it.

Sort First. Then Sweep. That's the Whole Section.

Best Time to Buy and Sell Stock (#121) is one pass, O(n), O(1) space. Track the minimum price seen so far. At each step, the max profit is the current price minus that minimum. The follow-up rounds (multiple transactions, cooldown, fees) use real DP and appear in SDE2 phone screens.

Maximum Subarray (#53) introduces Kadane's algorithm. At each position, decide whether to extend the existing subarray or start fresh: current = max(num, current + num). Initialize current to nums[0], not 0, or you break on all-negative inputs. That edge case appears in follow-ups at Microsoft even when the base problem is posed as easy. Zero sounds safe. It is not.

Merge Intervals (#56) is a sorting problem first. Sort by start time. Sweep through and either extend the current interval if next_start <= current_end, or push it and start fresh. The off-by-one: overlap is <=, not <. An interval starting exactly where the current one ends should merge.

Interviewer asks candidate to sort an array of 0s, 1s, and 2s. Candidate starts with bubble sort. Interviewer: "My grandma runs faster than your code."

Sort by start time. Not by vibes.

See Dynamic Programming Bugs That Pass Every Obvious Test Case for the edge cases that surface under interview pressure.

Word Break: DP Wearing a Search Disguise

Word Break (#139) shows up in Microsoft loops, especially at SDE2. The state is dp[i] meaning the prefix of length i can be segmented. Fill it forward: for each position i where dp[i] is true, iterate through words and mark dp[i + len(word)] true if the substring matches. The hash set lookup for words is the detail that makes this O(n * k) instead of O(n * k * w) where w is word length. Candidates who reach for a Trie get extra credit, though it is not required.

Reverse Linked List Is the Warmup, Not the Problem

Reverse Linked List (#206) is easy. Microsoft uses it as a setup before asking you to reverse a sublist, reorder a list in place, or find the middle using fast and slow pointers. Know the iterative three-pointer version cold.

When asked about the recursive version, mention that it uses O(n) stack space. That is a real constraint on long lists. They are not asking because recursion is pretty. They are asking to see if you know what it costs.

How to Prepare for Microsoft Coding Interviews

Work by pattern, not by problem number. Solve Two Sum and Group Anagrams back-to-back so the hash map instinct is automatic. Solve Level Order, Construct, and Diameter together so you stop treating each tree problem as a standalone puzzle.

Once you can solve all 15 clean, put yourself under time pressure: 20 minutes for easy problems, 35 for medium. That matches what you get in a Microsoft phone screen. After that, practice talking through your approach before touching the keyboard. Microsoft scores communication alongside correctness, and narrating the first two minutes before coding is what separates SDE from SDE2 candidates on borderline calls.

Voice-based practice builds that skill faster than silent LeetCode grinding. SpaceComplexity runs mock interviews in a real interview format, with rubric scoring across communication, problem-solving, and code quality, the same dimensions Microsoft evaluates in every round.

For the full picture of the Microsoft interview loop, see the Microsoft Software Engineer Interview guide.

Further Reading