
Microsoft Interview Questions
42 real coding interview questions recently asked at Microsoft, spanning Arrays and Strings, Linked Lists, Trees and Graphs, and 1 more topic, with a real difficulty tag and a direct LeetCode link for every question.
By DevsUnite · 42 Problems
Total Problems: 42Difficulty Levels:EasyMediumHard
Given an array and a target, find the two indices whose values sum to the target, typically solved in a single pass using a hash map that stores each value's complement as it's seen. It requires no advanced technique, which is exactly the point — it's a fast, low-friction warm-up used to confirm a candidate can reach for a hash map instead of defaulting to a brute-force O(n^2) nested loop.
Two sorted arrays need to be merged in place into the first array, which has extra trailing space to accommodate the second. The efficient approach fills from the back (largest elements first) with three pointers, avoiding the overwrite problem that a naive front-to-back merge would hit. It's a simple but effective test of whether a candidate can reason about in-place array manipulation direction rather than just knowing the merge-step of merge sort.
Find the contiguous subarray with the largest sum, the textbook application of Kadane's algorithm: track the best sum ending at the current index (either extend the previous subarray or start fresh at the current element) alongside a running global maximum. It's one of the most fundamental dynamic-programming-style problems in interviewing, testing whether a candidate has the core DP intuition of 'best solution ending here' down cold.
Find the length of the longest substring without repeating characters, the canonical sliding-window problem: maintain a window with two pointers and a hash map/set tracking the last-seen index of each character, jumping the left pointer forward whenever a repeat is found. It's one of the most fundamental sliding-window problems in interviewing and is often used to confirm a candidate can move beyond brute-force substring enumeration to a linear-time two-pointer approach.
Given a matrix, any cell containing zero must have its entire row and column zeroed out, and the interesting constraint is doing this in O(1) extra space. The standard trick reuses the matrix's own first row and first column as marker storage for which rows/columns need zeroing, with a couple of extra flags to avoid corrupting the markers themselves. It's a good test of in-place space-optimization thinking, since the brute-force O(m+n) auxiliary-array solution is easy but the constant-space version requires more careful reasoning.
Rotate an n x n matrix 90 degrees clockwise in place. The common technique is to transpose the matrix (swap elements across the diagonal) and then reverse each row, though a layer-by-layer four-way swap also works. It's a compact test of in-place matrix manipulation and geometric/index reasoning without needing any extra data structure.
This is the classic Dutch National Flag problem: sort an array containing only three distinct values (commonly 0, 1, 2) in a single pass using three pointers (low, mid, high) that partition the array into three regions as they scan. It tests whether a candidate can implement in-place three-way partitioning correctly, including the subtlety of not advancing the mid pointer after a swap with the high pointer. It's a frequently reused building block in quicksort-style partitioning, so it also signals whether that broader pattern is understood.
Given two strings, determine whether one contains a permutation of the other as a substring, solved with a fixed-size sliding window and character-frequency comparison (arrays or hashmaps) rather than generating and checking permutations directly. It tests whether a candidate recognizes that "contains a permutation of" reduces to "contains a window with the same character-count multiset," and can maintain that count incrementally as the window slides rather than recomputing it from scratch each time. This is a strong signal for general sliding-window fluency, a pattern that recurs across many string and array problems.
A stack-simulation problem: asteroids move left or right, and colliding pairs are resolved by comparing sizes and directions according to a small set of rules. The stack holds asteroids that haven't yet been destroyed, and each new asteroid may trigger a cascade of comparisons against the stack top before it's pushed or discarded. It's a good test of careful, exhaustive case enumeration (which asteroid survives, ties, same-direction pairs) rather than algorithmic complexity.
Given an elevation map, compute how much water it can trap after rain — the water trapped at each index equals the shorter of the tallest bars to its left and right, minus its own height. It's solvable with two pointers in O(1) extra space, with a monotonic stack, or with two precomputed max-prefix/max-suffix arrays, making it a great vehicle for comparing multiple valid techniques in one interview. Its breadth of companies asking it reflects that it's one of the most widely used checks of two-pointer/array reasoning in the entire interview circuit.
Given an array of heights, find two lines that, together with the x-axis, form the container holding the most water. The optimal solution uses two pointers starting from both ends, always moving the pointer at the shorter line inward (since moving the taller one can never increase the area), tracking the best area seen. It tests two-pointer greedy reasoning and, more importantly, whether a candidate can articulate why the greedy move is provably safe rather than just applying it by rote.
This asks for the longest contiguous palindromic substring, typically solved by expanding around each possible center (accounting for both odd- and even-length palindromes) in O(n^2), or via dynamic programming over substring start/end pairs, with Manacher's algorithm as the O(n) approach for candidates who know it. It's a common medium-difficulty string problem that tests careful index handling and awareness of the difference between substrings and subsequences. Interviewers often use it to see whether a candidate can identify and handle the odd/even-length edge case cleanly.
A classic in-place array algorithm: find the rightmost position where the sequence stops strictly increasing (scanning from the right), swap that element with the smallest element to its right that's still larger than it, then reverse the suffix to get the smallest lexicographic arrangement greater than the current one. It tests whether a candidate knows or can derive this specific non-obvious three-step algorithm, since a naive approach (generating and sorting all permutations) doesn't scale. It's a strong signal for algorithmic pattern recognition, since the technique itself, not just the coding, is the crux of the problem.
A binary-search problem: find a target value's index in a rotated sorted array in O(log n) time. It tests whether a candidate can identify which half of the array around the midpoint is properly sorted at each step, then decide whether the target falls within that sorted half or the other one. Its wide reach across companies reflects how well it isolates genuine binary-search intuition from candidates who only know the textbook sorted-array version.
The task is to return all elements of a matrix visited in spiral order, typically implemented by maintaining four shrinking boundaries (top, bottom, left, right) and walking each edge in turn before tightening the boundaries inward. It's less about algorithmic complexity and more about careful index management and avoiding off-by-one errors or double-counting the last row/column when the matrix isn't square. It's a common signal for whether a candidate can translate a visual/spatial pattern into precise, boundary-safe loop logic.
A classic backtracking problem: search a 2D letter grid for a given word by trying each cell as a starting point and exploring adjacent cells via DFS, marking cells visited during the current path and unmarking them (backtracking) before trying alternate paths. It tests whether a candidate can correctly manage mutable visited state across a recursive search and prune paths early when a character mismatch occurs. It's a strong signal for general backtracking competence, a technique that generalizes to many other constraint-search problems.
A Hard-tier array problem solved with an in-place, index-as-hash-table technique: you place each positive number ≤ n at its correct index (value v goes to index v-1) via swaps, then scan for the first index whose value doesn't match, all within O(n) time and O(1) extra space. It tests whether a candidate can find a genuinely non-obvious optimal solution rather than the natural but disallowed approach (a hash set), since the O(1)-space constraint is the entire point of the problem. It's a strong signal for algorithmic creativity under a tight space constraint, commonly used to differentiate strong candidates in a Hard-tier slot.
Given an array where each element is the maximum jump length from that position, the goal is to find the minimum number of jumps to reach the last index, solved greedily by tracking the farthest reachable index within the current "jump level" (an implicit BFS over reachability ranges rather than over individual indices). It tests whether a candidate can find the greedy invariant that avoids exponential branching from trying every possible jump length at each step. This greedy-versus-brute-force distinction is a common signal for optimization-style array problems.
Find all unique triplets in an array that sum to zero. The standard approach sorts the array, then for each element uses a two-pointer sweep over the remaining elements, carefully skipping duplicate values to avoid repeated triplets in the output. It extends the simpler two-pointer/two-sum pattern into a triplet setting and tests whether a candidate can handle the deduplication logic correctly, which is where most candidates lose points.
Compute, for each index, the product of all array elements except the one at that index, without using division. The standard O(1)-extra-space solution builds a running prefix product and running suffix product in two passes, multiplying them together for the final answer. It tests array manipulation and space-optimization thinking — specifically whether a candidate can avoid the naive division-based shortcut and still hit optimal time and space.
This is a string-parsing/simulation problem that mimics the C `atoi` function: skip leading whitespace, handle an optional sign, consume digits until a non-digit character, and clamp the result to 32-bit signed integer bounds. There's no complex algorithm involved -- the difficulty is entirely in correctly handling the long list of edge cases (empty string, sign-only input, overflow, trailing garbage) without missing one. It's a strong signal for meticulous, defensive coding under a spec with many corner cases, which mirrors real-world input-validation work.
Log in to save your progress, favorites, and notes to your account.
Frequently asked questions
What coding interview questions does Microsoft ask?
This page tracks 42 real, recently reported Microsoft coding interview questions, organized by topic: Arrays and Strings, Linked Lists, Trees and Graphs, and 1 more topic.
How many Microsoft interview questions are on this list?
42 questions in total: 4 Easy, 30 Medium, and 8 Hard, each linked to its real LeetCode problem page.
Is it free to use?
Yes. Browsing every problem on this page is completely free, with no account required. Creating a free DevsUnite account lets you save your checked-off progress, star favorites, and add personal notes that sync across devices.
Do I need an account to track my progress?
You can read and solve every problem without logging in. An account is only required to mark a problem as done, star it, or add a note. Those actions save to your account instead of resetting on refresh.