Microsoft Coding Interview Questions
20 Microsoft coding interview problems with full optimal solutions — 5 easy, 13 medium, 2 hard. Every problem ships with multiple approaches (brute-force first, then the optimal), complexity tables for each, company-specific tips on what an Microsoft interviewer values, and a FAQ section.
- #20easyfoundational
20. Valid Parentheses
Valid Parentheses is the Microsoft warm-up that tests whether you can pick the right data structure on the first try. The answer is always a stack — explain why before writing code, and use a closing-to-opening hash map so the matching logic is a single comparison.
4 free resourcesSolve → - #42hardfrequently asked
42. Trapping Rain Water
Trapping Rain Water is the Microsoft hard that separates the two-pointer fluent from the rest. Naive answer is O(n^2). DP with leftMax/rightMax arrays is O(n) time + O(n) space. The two-pointer version is O(n) time + O(1) space — the bonus the interviewer is hoping you reach.
4 free resourcesSolve → - #46mediumfrequently asked
46. Permutations
Permutations is Microsoft's introduction to backtracking. Given distinct integers, generate every ordering. The standard template — pick, recurse, unpick — is what the interviewer is grading; the in-place swap variant is the bonus answer for the same complexity in less memory.
4 free resourcesSolve → - #54mediumfrequently asked
54. Spiral Matrix
Spiral Matrix is Microsoft's most-asked matrix-traversal question. The interviewer is grading whether you can manage four shrinking boundaries (top, bottom, left, right) without an off-by-one bug at the moment two boundaries cross in the middle of a row or column.
4 free resourcesSolve → - #56mediumfrequently asked
56. Merge Intervals
Merge Intervals is the Microsoft sort-then-sweep classic. Sort intervals by start, then walk left to right merging into the previous interval whenever the current start is <= previous end. The interviewer wants you to name 'sort plus single pass' as the structure before coding.
4 free resourcesSolve → - #98mediumfrequently asked
98. Validate Binary Search Tree
Validate Binary Search Tree is the classic Microsoft tree question that punishes the obvious-but-wrong solution: comparing each node only to its immediate children. The interviewer wants the (min, max) bounds recursion or the in-order traversal, and grades the failure case you missed.
4 free resourcesSolve → - #103mediumfrequently asked
103. Binary Tree Zigzag Level Order Traversal
Binary Tree Zigzag Level Order Traversal is Microsoft's BFS-with-a-twist medium. Do a normal level-order BFS, then reverse alternate levels at the end. The cleaner trick is using a deque-as-output and toggling push direction every level.
4 free resourcesSolve → - #138mediumfrequently asked
138. Copy List with Random Pointer
Copy List with Random Pointer is Microsoft's classic deep-clone test. The trick is mapping each original node to its clone so the random pointer (which might point forward into yet-uncloned territory) lands on the right copy. Two passes with a hash map is the standard answer; O(1) space with interleaving is the bonus.
4 free resourcesSolve → - #139mediumfrequently asked
139. Word Break
Word Break is Microsoft's introduction to dynamic programming on strings. The dp[i] = 'is s[0..i] segmentable' framing turns an exponential recursion into a linear-in-n^2 fill. Interviewers want to see you reject memoized DFS as a path to the same answer.
4 free resourcesSolve → - #151mediumfrequently asked
151. Reverse Words in a String
Reverse Words in a String is Microsoft's go-to string-manipulation question. The clean two-liner (split, reverse, filter, join) is acceptable but interviewers grade highly on the in-place O(1) version that reverses the whole string then reverses each word.
4 free resourcesSolve → - #168easyfrequently asked
168. Excel Sheet Column Title
Excel Sheet Column Title is Microsoft's deliberately-off-by-one base-26 puzzle. Excel columns A..Z, AA..AZ, BA.. are 1-indexed with no zero digit, so a vanilla base-26 conversion is wrong. The fix is subtracting one before every modulo.
4 free resourcesSolve → - #202easyfrequently asked
202. Happy Number
Happy Number is Microsoft's favorite cycle-detection question disguised as math. The trick is recognizing the digit-square sum sequence either reaches 1 or enters a cycle — so Floyd's tortoise-and-hare applies and the space drops to O(1).
4 free resourcesSolve → - #206easyfoundational
206. Reverse Linked List
Reverse Linked List is Microsoft's go-to pointer-manipulation warm-up. Interviewers want you to talk through the three-pointer dance (prev, curr, next) without losing the rest of the list and to mention the recursive variant before they ask.
4 free resourcesSolve → - #207mediumfrequently asked
207. Course Schedule
Course Schedule is Microsoft's cycle-detection-on-a-directed-graph staple. The question is 'can you finish all courses' which reduces to 'is the prereq graph a DAG.' Two valid answers — DFS with three-state coloring or Kahn's BFS — both score full marks if you can articulate why.
4 free resourcesSolve → - #208mediumfrequently asked
208. Implement Trie (Prefix Tree)
Implement Trie is the Microsoft data-structure design medium. The clean answer is a node class with a children object and an isEnd flag. Microsoft cares that you can write insert, search, and startsWith without mixing them up — they share traversal logic but stop on different conditions.
4 free resourcesSolve → - #277mediumfrequently asked
277. Find the Celebrity
Find the Celebrity is Microsoft's elegant elimination puzzle. With n people and a knows(a,b) oracle, brute force is O(n^2). The two-pointer elimination trick gets it to O(n) calls — and the verification pass is what makes the candidate proof bulletproof.
4 free resourcesSolve → - #297hardfrequently asked
297. Serialize and Deserialize Binary Tree
Serialize and Deserialize Binary Tree is Microsoft's litmus test for whether you can design a custom encoding and parse it back. The pre-order DFS with explicit null markers is the standard answer; the interviewer is grading whether your serializer and deserializer agree on exactly how nulls are represented.
4 free resourcesSolve → - #380mediumfrequently asked
380. Insert Delete GetRandom O(1)
Insert Delete GetRandom O(1) is Microsoft's go-to data-structure design medium. The trick is pairing an array (for O(1) random access by index) with a hash map (for O(1) value lookup), then doing the swap-with-last trick on delete.
4 free resourcesSolve → - #438mediumfrequently asked
438. Find All Anagrams in a String
Find All Anagrams in a String is Microsoft's clean sliding-window-with-frequency-matching question. Maintain a window of length p over s; compare frequencies on each slide. The clever variant — track only a diff counter instead of comparing maps — is the optimization Microsoft hopes you reach.
4 free resourcesSolve → - #703easyfrequently asked
703. Kth Largest Element in a Stream
Kth Largest Element in a Stream is Microsoft's go-to question for whether you reach for the right data structure when 'streaming' enters the problem. The answer is a min-heap of size k — anything else (sorted list, max-heap) has the wrong asymptotic cost.
4 free resourcesSolve →
Related interview-prep guides
HireVue Tech Interview Guide: The 2026 Playbook for Async Video Rounds
HireVue is the category-leading async video interview platform. Candidates record answers solo, on the clock, and a combined AI-plus-human review layer scores the recording days later. For 2026 tech jobseekers, the format is different enough from live interviews to need its own playbook. This guide is that playbook.
Codility for Tech Interviews in 2026: The Complete Guide for Candidates
Codility is the dominant algorithmic-assessment platform across European tech hiring. Heavy in the UK, Germany, Netherlands, Nordics, and Poland where the company was founded. It scores candidates on both correctness and time complexity, runs 60-to-120-minute timed tests, and ships three products: Tests, CodeCheck, and CodeLive. This guide is what 2026 candidates need to know.
LeetCode Assessments: The 2026 Tech Interview Guide
LeetCode Assessments is the enterprise tier of the LeetCode platform: a separate product from the public site candidates know from grinding problems. Companies pay LeetCode to build custom timed assessments that draw from the 3,000-problem public catalog plus optional private variations, and the catalog asymmetry is the whole story for prep.