Microsoft Software Engineer Coding & Algorithms Interview Questions
Master your tech interview with our curated database of real questions from top companies.
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...
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 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...
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...
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 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...
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...