Microsoft Coding & Algorithms Interview Questions
Master your tech interview with our curated database of real questions from top companies.
Solve two-pointer, sliding-window, and string tasks
Solve the following three coding tasks: 1) Two-pointer in-place de-duplication: Given a non-decreasing integer array nums and an integer k >= 1, modif...
Implement lower_bound on unknown-size sorted array
Lower Bound in Unknown-Length Nondecreasing Array via API Setup You are given a non-decreasing integer array A of unknown length n. You cannot access ...
Implement rotated array binary search with duplicates
Given an integer array nums that is a non-decreasing array rotated an unknown number of times. Duplicates may exist. Implement a function that returns...
Reverse a list in-place
Coding Task: Reverse a List In-Place (Python) Context You're implementing a utility function during a technical screen. The function must reverse a Py...
Count non-decreasing arrays by digit sums
You are given an array required_sums of length n. Count how many non-decreasing arrays result[1..n] of integers satisfy all of the following: ( 1) for...
Implement tree traversals, BFS, and subsets generation
1) Define a TreeNode class for a binary tree with an integer value and left/right pointers. Implement preorder, inorder, and postorder traversals: (a)...
Count k for consecutive-sum generator
An array generator service produces a consecutive-integers array starting at a positive integer k: [k, k+1, ..., k+m−1] for some m ≥ 1. The service re...
Solve load balancing and perfect pairs
1) Contiguous load balancing: You have n identical resources (servers) and m ordered tasks with processing times burstTime[0..m-1]. Each server must b...
Maximize profit with bounded sell window
Given an array prices[0..n-1] of daily stock prices and an integer D ≥ 1, you may perform at most one transaction (buy then sell). The sell day j must...
Implement a generic tree Node class
Design and implement a Node class for a mutable rooted tree. Requirements: store value, parent, and ordered children; support add_child, remove, move_...
Determine dictionary-based string segmentation
You are given a string s and a set of tokens dict. Determine whether s can be segmented into a sequence of one or more tokens from dict. If segmentati...
Solve binary-search knapsack & graph shortest path
Question Given a sorted list of items, design an efficient solution (using binary search) to achieve the target objective instead of a dynamic-program...
Determine most popular concert city
Question Given a set of concert venue vote records, determine which city is the most popular. How would you normalize city names that have multiple sp...
Solve budget queries and shortest path
1) Budgeted purchases with sorted array: You are given an array prices of n positive integers and q budget queries. For each budget B, you may buy ite...
Compute sum of longest positive subarray
Given an integer array that may contain positive and negative numbers, find the sum of the longest contiguous subarray consisting only of positive num...