Microsoft Coding & Algorithms Interview Questions
Practice the exact questions companies are asking right now.
Solve binary-tree reverse printing and LPS
You are given a binary tree node definition: - TreeNode { int val; TreeNode left; TreeNode right; } Answer the following two algorithmic questions. 1)...
Assemble DNA payload strings from tagged fragments
You are given a list of DNA-like fragments. Each fragment is a tuple: - start_tag: string - end_tag: string - payload: string A valid DNA chain is for...
Solve four classic algorithm problems
You are given four independent coding tasks. For each task, implement the required function. --- Problem 1: Zigzag level-order traversal of a binary t...
Find longest substring without repeating characters
Problem Given a string s, return the length of the longest contiguous substring that contains no repeated characters. Input - s: a string (may contain...
Implement a calendar with non-overlapping bookings
Problem Design a calendar booking system that stores half-open time intervals [start, end) (inclusive of start, exclusive of end). Implement a class w...
Merge overlapping intervals
You are given an array of intervals, where each interval is represented as a pair of integers [start, end] with start <= end. The intervals may be uns...
Find lowest common ancestor in tree
You are given the root of a binary search tree (BST) and two distinct nodes p and q that are guaranteed to exist in the tree. Task (BST case): - Find ...
Count integer pairs satisfying 1/x + 1/y = 1/N
You are given a positive integer N (\(1 \le N \le 10^6\)). Consider the Diophantine equation: \[ \frac{1}{x} + \frac{1}{y} = \frac{1}{N}, \] where x a...
Find max consecutive elements with sum below target
You are given: - An integer array nums of length n, sorted in non-decreasing order. - An integer index such that 0 ≤ index < n. - An integer target. S...
Find shortest substring with n unique letters
Problem You are given a string s consisting of lowercase English letters and an integer n (1 ≤ n ≤ 26). Find the length of the shortest contiguous sub...
Solve three scheduling and array problems
In this round you are given three separate coding problems to solve. --- Problem 1: Schedule tasks with cooldown You are given: - A list of tasks, whe...
Reverse linked list in fixed-size groups
Problem You are given the head of a singly linked list and an integer k (k >= 1). Reverse the nodes of the list in-place in groups of size k: - The no...
Merge multiple sorted arrays using min-heap
Problem You are given k sorted arrays of integers: - arrays[0], arrays[1], ..., arrays[k-1] - Each arrays[i] is sorted in non-decreasing order. - The ...
Design cache with least-recently-used eviction
You are asked to design an in-memory key–value cache that supports a least-recently-used (LRU) eviction policy. The cache must support the following o...
Build a time-based key-value store
Problem Design a data structure that stores multiple values for the same key at different timestamps, and can retrieve the most recent value as of a g...
Implement a Tic-Tac-Toe game class
Problem Implement a class that supports playing an n × n Tic-Tac-Toe game. Requirements Create a class TicTacToe(n) with: - move(row, col, player) -> ...
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...