Microsoft Recent SDE2 DSA Queations

microsoft logo
microsoft
SDE II
August 26, 202548 reads

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.

Full Experience

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.

Interview Questions (16)

Q1
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.

Q2
Time Based Key-Value Store
Data Structures & AlgorithmsMedium

Design a time-based key-value store that supports set and get operations. The set operation stores a key with a value and a timestamp. The get operation 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.

Q3
Determine if Two Strings Are Close with Word Ladder Follow-up
Data Structures & AlgorithmsMedium

Determine 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.

Q4
Remove K Digits
Data Structures & AlgorithmsMedium

Given a non-negative integer num represented as a string, remove k digits from the number so that the new number is the smallest possible. The length of num is less than 10002 and will be >= k.

Q5
Spiral Matrix
Data Structures & AlgorithmsMedium

Given an m x n matrix, return all elements of the matrix in spiral order.

Q6
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.

Q7
3Sum
Data Structures & AlgorithmsMedium

Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j, i != k, and j != k, and nums[i] + nums[j] + nums[k] == 0. Notice that the solution set must not contain duplicate triplets.

Q8
Subarray Sum Equals K
Data Structures & AlgorithmsMedium

Given an array of integers nums and an integer k, return the total number of contiguous subarrays whose sum equals to k.

Q9
Group Anagrams
Data Structures & AlgorithmsMedium

Given 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.

Q10
Find All Peak Elements in Array
Data Structures & AlgorithmsMedium

Given 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.

Q11
Valid Parentheses
Data Structures & AlgorithmsEasy

Given a string s containing 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.

Q12
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).

Q13
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.

Q14
Delete Node in a Linked List
Data Structures & AlgorithmsEasy

Write 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.

Q15
Reconstruct Itinerary
Data Structures & AlgorithmsHard

You 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.

Q16
Maximum Profit of Contiguous Subarray (Length at most K)
Data Structures & Algorithms

You are given an integer array pnl of length n, where pnl[i] represents the profit or loss on day i. You are also given an integer k. Your task is to find the maximum possible profit of any contiguous subarray whose length is at most k.

Discussion (0)

Share your thoughts and ask questions

Join the Discussion

Sign in with Google to share your thoughts and ask questions

No comments yet

Be the first to share your thoughts and start the discussion!