Microsoft Recent SDE2 DSA Queations
- Posted
- 26 Aug 2025
Summary
I've compiled a set of Data Structures and Algorithms questions that were recently posed in SDE2 interviews at Microsoft, shared by myself and my friends.
How it went
This post is a collection of Data Structures & Algorithms questions that I and a few of my friends encountered during our recent SDE2 interviews at Microsoft. Our aim is to provide valuable insights into the types of problems asked for this role, ranging from standard LeetCode problems to custom algorithmic challenges and even a system design question. These questions were gathered from various rounds we faced, including some with direct LeetCode links and others described in detail. Hopefully, this comprehensive list will aid others preparing for similar roles.
Questions asked (16)
- 01
Minimize String Partitions
Data Structures & Algorithms
You are given a string s = "31415926535 8979323846264338327" and a list of words: ["314", "15926535 89", "79323846264", "338327", "7932", "3846264", "338327"]. Your task is to partition the string s into substrings such that:
- Each substring is present in the given list of words.
- The number of partitions (substrings) is minimized.
- 02
Time Based Key-Value Store
Data Structures & Algorithms · Medium
Open the problemDesign a time-based key-value store that supports
setandgetoperations. Thesetoperation stores a key with a value and a timestamp. Thegetoperation retrieves the value associated with a key at a specific timestamp, returning the most recent value if multiple exist before or at the given timestamp. - 03
Determine if Two Strings Are Close with Word Ladder Follow-up
Data Structures & Algorithms · Medium
Open the problemDetermine if two strings are 'close' based on specific operations (swap any two existing characters, or transform every occurrence of one existing character into another existing character, and vice versa). A follow-up problem, similar to 'Word Ladder', was also discussed.
- 04
Remove K Digits
Data Structures & Algorithms · Medium
Open the problemGiven a non-negative integer
numrepresented as a string, removekdigits from the number so that the new number is the smallest possible. The length ofnumis less than 10002 and will be >= k. - 05
Spiral Matrix
Data Structures & Algorithms · Medium
Open the problemGiven an m x n
matrix, return all elements of thematrixin spiral order. - 06
Design Text Editor with Undo/Redo
System Design
Design a text editor that supports basic operations like typing, deleting, and cursor movement, along with undo and redo functionalities. Several follow-up questions were also part of this problem.
- 07
3Sum
Data Structures & Algorithms · Medium
Open the problemGiven an integer array
nums, return all the triplets[nums[i], nums[j], nums[k]]such thati != j,i != k, andj != k, andnums[i] + nums[j] + nums[k] == 0. Notice that the solution set must not contain duplicate triplets. - 08
Subarray Sum Equals K
Data Structures & Algorithms · Medium
Open the problemGiven an array of integers
numsand an integerk, return the total number of contiguous subarrays whose sum equals tok. - 09
Group Anagrams
Data Structures & Algorithms · Medium
Open the problemGiven an array of strings
strs, group the anagrams together. You can return the answer in any order. An Anagram is a word or phrase formed by rearranging the letters of a different word or phrase, typically using all the original letters exactly once. - 10
Find All Peak Elements in Array
Data Structures & Algorithms · Medium
Open the problemGiven an integer array
nums, find all the peak elements. A peak element is an element that is strictly greater than its neighbors. If there are multiple peaks, return all of them. - 11
Valid Parentheses
Data Structures & Algorithms · Easy
Open the problemGiven a string
scontaining just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid. An input string is valid if: Open brackets must be closed by the same type of brackets. Open brackets must be closed in the correct order. Every close bracket has a corresponding open bracket of the same type. - 12
Sort Array by Set Bit Count
Data Structures & Algorithms
Given an integer array, sort the integers in ascending order based on the count of their set bits (1s in binary representation). If two numbers have the same count of set bits, maintain their relative order as in the original array (or sort by value if not specified, but typically stability is preferred).
- 13
Remove Spaces from Character Vector In-place
Data Structures & Algorithms
Given a mutable sequence of characters (e.g.,
std::vector<char>or a character array), remove all spaces from it in-place. The relative order of non-space characters must be preserved. - 14
Delete Node in a Linked List
Data Structures & Algorithms · Easy
Open the problemWrite a function to delete a node (except the tail) in a singly linked list, given only access to that node. The given node will not be the tail and it will always be a valid node of the linked list.
- 15
Reconstruct Itinerary
Data Structures & Algorithms · Hard
Open the problemYou are given a list of airline tickets where
tickets[i] = [fromi, toi]represent the departure and arrival airports of one flight. Reconstruct the itinerary in order. All of the tickets belong to a man who departs from 'JFK'. Thus, the itinerary must begin with 'JFK'. If there are multiple valid itineraries, you should return the itinerary that has the smallest lexical order when read as a single string. For example, the itinerary["JFK", "LGA"]has a smaller lexical order than["JFK", "LGB"]. All airports are represented by three uppercase English letters. You may assume that there exists at least one valid itinerary. - 16
Maximum Profit of Contiguous Subarray (Length at most K)
Data Structures & Algorithms
You are given an integer array
pnlof lengthn, wherepnl[i]represents the profit or loss on dayi. You are also given an integerk. Your task is to find the maximum possible profit of any contiguous subarray whose length is at mostk.