Microsoft logo

Microsoft Medium Interview Questions

16 medium-level practice questions for Microsoft technical interviews

Microsoft software engineer interviews cover algorithms, data structures, system design, and coding problems drawn from real interview rounds.

Software Engineer Backend Engineer Frontend Engineer Full Stack Engineer Mobile Engineer Data Engineer Data Scientist ML Engineer DevOps Engineer DevOps Engineer Product Manager SRE Security Engineer Engineering Manager Data Analyst UX/UI Designer QA Engineer
coding Medium Verified Question #1

1. Design Rate Limiter


Category: Sliding window coding problem

Design Rate Limiter Design a rate limiter system that controls the number of requests allowed within a specified time window. The rate limiter is...

Input: String
Output: Computed result
coding Medium Verified Question #2

2. Object Oriented Design - Idempotent Receipt Sending


Category: Trie-based coding problem
Input: String
Output: Computed result
coding Medium Verified Question #3

3. Object Oriented Design - Notification Service


Category: Trie-based coding problem

Problem Statement Design a notification service that supports sending notifications through multiple channels (SMS, Email) and is architected to...

Input: Number(s)
Output: Computed result
coding Medium Verified Question #4

4. Shortest Substring with N Unique Characters


Category: String coding problem

Shortest Substring with N Unique Characters *This is a variation of the leetcode problem* Given a string s and an integer n, find the length of...

Input: String
Output: Computed result
coding Medium Verified Question #5

5. Bounded Repeat Substring


Category: String coding problem
A sensor data stream is represented as a string of characters. A contiguous segment of the stream is considered valid if it contains no three...
Input: String
Output: Computed result
coding Medium Verified Question #6

6. OA [CodeSignal] Prime Jumps


Category: Algorithm coding problem

OA [CodeSignal] Prime Jumps A game is played with the following rules: - A player starts at cell 0 with a score of 0. - There is a row of n cells...

Input: Number(s)
Output: Computed result
coding Medium Verified Question #7

7. Digit Replacement Maximizer


Category: String coding problem
A numeric optimization system performs exactly k substitution operations on a number string s. In each operation, choose any digit in s that is...
Input: String
Output: Computed result
coding Medium Verified Question #8

8. Best Window For Target Count


Category: Trie-based coding problem
A log analysis tool searches for the most frequent occurrence of a specific error code within a fixed-size window of log entries. Given an integer...
Input: Array
Output: Integer
coding Medium Verified Question #9

9. Evens Before Odds


Category: Array coding problem
You are given an integer array nums. Rearrange nums so that all even numbers appear before all odd numbers. The relative order of even or odd...
Input: Array
Output: Integer
coding Medium linked list #1

1. Reverse a Linked List — Manipulating Linked List Pointers

This problem is common in manipulating linked lists, which are used in many Microsoft applications, including data structures in Azure services.
Problem statement: Given the head of a singly linked list, return the head of the list after reversing it. You need to reverse the list in-place, which means you should not use extra space for another list.
Function/class signature:
  • def reverse_linked_list(head: Optional[ListNode]) -> Optional[ListNode]:


Example 1:
  • Input: head = [1, 2, 3, 4, 5]

  • Output: [5, 4, 3, 2, 1]

  • Explanation: After reversing, the last element becomes the head.


Example 2:
  • Input: head = [1]

  • Output: [1]

  • Explanation: A single node remains unchanged when reversed.


Constraints:
  • The number of nodes in the list is in the range [0, 5000].

  • -5000 <= Node.val <= 5000.

  • The input list is guaranteed to have at least one node.


coding Medium linked list #2

2. Reverse a Linked List — Implement a function to reverse a singly linked list

Background: Reversing a linked list is a common operation in various data structures and can be essential in memory management of linked data. For Microsoft products that utilize linked lists for managing dynamic data, efficient reversing can significantly improve performance in data traversal tasks.
Problem statement: You are given a singly linked list with the head node head. Your task is to reverse the linked list and return the new head node. Ensure that the function can handle edge cases such as an empty list or a single node list.
Function/class signature:
  • def reverse_linked_list(head: Optional[Node]) -> Optional[Node]:

Example 1:
Input: head = 1 -> 2 -> 3 -> None
Output: 3 -> 2 -> 1 -> None
Explanation: The linked list is reversed from 1 -> 2 -> 3 to 3 -> 2 -> 1.
Example 2:
Input: head = None
Output: None
Explanation: The input is an empty list, so the output is also None.
Constraints:
  • The number of nodes in the list is in the range [0, 5000].

  • The values of the nodes are integers between -1000 and 1000.

  • The nodes of the linked list are unique.
coding Medium linked list #3

3. Coding — Reversing a Linked List

Background: Microsoft often works with complex data structures in its software, and understanding linked lists is crucial for optimizing performance in these systems. This exercise simulates data manipulation relevant in environments like Azure or Microsoft 365.
Problem statement: Given a singly linked list, reverse the list and return the new head of the reversed linked list. You need to ensure your solution runs in O(n) time and O(1) space complexity.
Function/class signature:
  • def reverse_linked_list(head: Optional[ListNode]) -> Optional[ListNode]:

Example 1:
Input: 1 -> 2 -> 3 -> 4 -> 5 -> None
Output: 5 -> 4 -> 3 -> 2 -> 1 -> None
Explanation: The linked list is reversed from its original order.
Example 2:
Input: 1 -> None
Output: 1 -> None
Constraints:
  • The list may be empty (head will be None).

  • The number of nodes in the list is within the range [0, 5000].
coding Medium linked list #4

4. Reversing a Linked List — in-place reversal of a linked structure

Background: Reversing a linked list is a common operation used in various algorithms and data processing tasks. Microsoft may require this for its applications dealing with data structures, especially in scenarios involving programming languages like C# where linked lists are prevalent in data representation.
Problem statement: Given a singly linked list, you need to reverse the linked list so that the head points to the last node and each node points to the previous node instead of the next node. The reversal should be done in-place without using extra space for another data structure.
Function/class signature:
  • def reverse_linked_list(head: ListNode) -> ListNode:

Example 1:
  • Input: head = [1, 2, 3, 4, 5]

  • Output: [5, 4, 3, 2, 1]

  • Explanation: The linked list gets reversed so 1 becomes 5, 2 becomes 4, and so on.

Example 2:
  • Input: head = [1]

  • Output: [1]

  • Explanation: A single element list remains unchanged.

Constraints:
  • The head of the list will have at least one node.

  • Node values can be any integer.

  • The maximum number of nodes does not exceed 10^4.
coding Medium caching #5

5. Implementing an LRU Cache — a pattern for caching responses or data

Background: Microsoft often handles large volumes of data where quick access to previously used data is critical for performance. An efficient caching mechanism like an LRU (Least Recently Used) Cache is necessary to optimize memory usage and speed up data retrieval in applications such as Azure services.
Problem statement: Design and implement an LRU Cache that supports the following operations: get(key) and put(key, value). The get method retrieves the value of the key if it exists in the cache. Otherwise, it returns -1. The put method will insert or update the value for a key. If the cache exceeds its capacity, it should invalidate the least recently used item before inserting a new item into the cache.
  • Function/class signature:

- def __init__(self, capacity: int): # Initializes the LRU cache with positive size capacity.
- def get(self, key: int) -> int: # Returns the value of the key if it exists in the cache, otherwise returns -1.
- def put(self, key: int, value: int) -> None: # Updates or inserts the value if the key is not already present. When the cache reached its capacity, it should invalidate the least recently used item.
Example 1:
  • Input: cache = LRUCache(2); cache.put(1, 1); cache.put(2, 2); cache.get(1)

  • Output: 1

  • Explanation: 1 was accessed and is now the most recently used.

Example 2:
  • Input: cache.put(3, 3)

  • Output: -1

  • Explanation: cache exceeds capacity. 2 is evicted.

Constraints:
  • The cache will have a capacity of at least 1 and at most 3000.

  • The keys and values will be integers ranging from 0 to 10^4.
coding Medium caching #6

6. Data Structures and Algorithms — Implement an LRU Cache

Background: Microsoft products often require efficient data retrieval and caching systems, particularly for performance optimization in applications like Azure and Windows services. Implementing an LRU cache allows for fast access to frequently used data while managing memory efficiently.
Problem statement: Design and implement a data structure that supports the following operations: get(key) and put(key, value). The get method retrieves the value of the key if it exists in the cache, otherwise returns -1. The put method updates or adds the value of the key in the cache. When the cache reaches its capacity, it should invalidate the least recently used entry before inserting a new item.
Function/class signature:
  • def __init__(self, capacity: int): # initialize LRUCache with positive size capacity

  • def get(self, key: int) -> int: # return the value of the key, or -1 if the key does not exist

  • def put(self, key: int, value: int) -> None: # update the value of the key or insert the key if it is not already present

Example 1:
Input: lru_cache = LRUCache(2)
lru_cache.put(1, 1)
lru_cache.put(2, 2)
print(lru_cache.get(1))
Output: 1
Explanation: Key 1 was found, returned 1.
Example 2:
Input: lru_cache.put(3, 3)
Output: None (cache evicts key 2)
Constraints:
  • 1 <= capacity <= 3000

  • 0 <= key <= 10^4

  • 0 <= value <= 10^8
coding Medium dynamic programming #7

7. Counting Palindromic Substrings — Count subsets of strings that are palindromes

Background: In applications like Microsoft Word or Microsoft Teams, analyzing text for formatting or categorizing can often benefit from identifying palindromic substrings to enhance features like spell-checkers or text analyzers.
Problem statement: Given a string s, you need to return the number of palindromic substrings in s. A palindrome is a string that reads the same backward as forward.
Function/class signature:
  • def count_palindromic_substrings(s: str) -> int:


Example 1: Input: "aaa", Output: 6, Explanation: Substrings are "a", "a", "a", "aa", "aa", "aaa".
Example 2: Input: "abc", Output: 3, Explanation: Substrings are "a", "b", "c".
Constraints:
  • 1 <= len(s) <= 1000

  • s consists of lowercase English letters.

Start practicing Microsoft questions

Sign up for free to access walkthroughs, AI-generated questions, and more.

Get Started Free