Microsoft coding interview

Round 4 of 5 · 94 questions reported

See the whole loop
Length
60 min
Format
Ten to fifteen minutes of behavioral questions, then coding in HackerRank where you write a main and make the tests pass; usually three rounds
They grade
Working code that passes the interviewer's tests
AI use
No AI unless the interviewer invites it; some 2026 loops add a round where you bring your own AI agent
Heads-up
Microsoft AI coding rounds use practical problems (an in-memory database, a beam search decoder, a data loader) rather than puzzles.

Questions Microsoft asks in this round 94

  • Implement an LRU cacheCodingImplement a least-recently-used cache with get(key) and put(key, value), both in O(1) time, with a fixed capacity.
    Last asked Aug 2026
  • In-memory SQL table with filtering and multi-key sortingCodingBuild a small in-memory SQL-like database. You do not need to parse SQL text. Queries arrive as structured arguments. Implement SQLManager: - createtable(name: str, columns:…
    Last asked May 2026
  • Reconstruct a string from chained segmentsCodingA log-shipping service splits a long message into fragments and sends them out of order. Each fragment is a triple startid, endid, payload: it covers the stretch from marker…
    Last asked May 2026
  • Greedy and beam search decoding for a language modelCodingYou are writing the decoding step for a language model. Decoding turns the model's per-step scores into a sequence of token ids. Implement greedydecode(scores: listlistfloat) -…
    Last asked Sep 2026
  • Per-key ordered task executor on a thread poolCodingBuild a component that takes a maximum concurrency and an existing thread-pool executor and exposes submit(key, task). Tasks with the same key must run one at a time in the order…
    Last asked Sep 2026
  • Word breakCodingReturn whether a string can be split into a sequence of words from a dictionary, where words may be reused. Give the dynamic programming solution and its cost.
    Last asked Aug 2026
  • Count the maximum in each queried suffixCodingYou are given an integer array nums of length n and an array query of 0-based start indices. For each index i in query, look at the suffix numsi, numsi+1, ..., numsn-1. Find the…
    Last asked Aug 2026
  • Thread safety and deadlocks, explained and demonstratedCodingA fast concepts round. What makes code thread-safe? Show the common ways a deadlock happens (for example two threads taking two locks in opposite order) and the ways to prevent…
    Last asked Aug 2026
  • Implement k-means clusteringCodingImplement k-means from scratch: initialize k centroids, assign every point to its nearest centroid, move each centroid to the mean of its points, and repeat until the assignments…
    Last asked Apr 2026
  • Binary tree zigzag level-order traversalCodingReturn a binary tree's values level by level, alternating direction: left to right on the first level, right to left on the next, and so on. Use a BFS by levels and reverse (or…
    Last asked Apr 2026
  • LRU cacheCodingBuild a key-value cache with a fixed capacity that evicts the least recently used entry when it is full. get(key) returns the value or a miss, put(key, value) inserts or updates…
    Last asked Apr 2026
  • Weighted data batcher with deterministic resumeCodingBuild a sampler that draws weighted batches from a dataset registry and can resume deterministically from a saved offset, including the edge case where the batch size does not…
    Last asked Mar 2026
  • Truncate model output at the first stop sequenceCodingImplement a function that returns the part of a string that comes before the earliest stop word. - text is any string. It may be empty. - stopwords is a list of non-empty strings…
    Last asked Mar 2026
  • Merge intervalsCodingGiven a list of intervals (for example time ranges), merge every group of overlapping intervals and return the result in sorted order.
    Last asked Feb 2026
  • Decode a JWT by hand and explain browser authenticationCodingExplain how a browser stays signed in with JWTs: how the token is issued, stored and sent, and how the server checks it. Then decode a JWT string without a library: split it into…
    Last asked Feb 2026
  • Sliding-window request rate limiterCodingImplement a rate limiter that accepts at most limit requests in any window of ttl milliseconds. - allow(timestamp) is called once per incoming request. timestamp is in…
    Last asked Feb 2026
  • Next greater palindromeCodingYou are given a string n holding a positive integer in decimal, with no leading zeros. It can be hundreds of digits long, so it may not fit in any built-in integer type. Return…
    Last asked Jan 2026
  • First value seen twice in a left-to-right scanCodingWalk an integer array from left to right and return the first value you meet for the second time, or -1 when no value repeats. The answer is decided by where the second occurrence…
    Last asked Sep 2026
  • Longest repeating character replacementCodingGiven a string of uppercase letters and an integer k, you may change at most k characters to any other letter. Return the length of the longest substring that can be made of one…
    Last asked Sep 2026
  • Most visited position on a circular trackCodingA race runs over a circular track of numbered sections, given as the order of sections it passes through. Return the section or sections visited most often. Only the title of this…
    Last asked Sep 2026
  • Convert a hexadecimal address to dotted IPv4CodingGiven a 32-bit address written in hexadecimal, return it in dotted-decimal IPv4 form, for example C0A80001 becomes 192.168.0.1. Decide and state how you treat an optional 0x…
    Last asked Aug 2026
  • Reconstruct digits from scrambled English number wordsCodingA string holds the shuffled letters of some English digit words (zero to nine). Recover the digits and return them in ascending order, repeats included. Explain the order in which…
    Last asked Aug 2026
  • Stable, unique column names across schema snapshotsCodingYou receive successive snapshots of table schemas and must give every column an effective name. Dots in an original name become underscores, and effective names must be unique…
    Last asked Aug 2026
  • Maximum subarray sum of an array repeated k timesCodingWrite an integer array out k times back to back and return the largest sum of a non-empty contiguous subarray of the result. Do it without building the repeated array, and explain…
    Last asked Aug 2026
  • Find the words in a list that are anagrams of a targetCodingGiven a target word and a list of words, return the entries that are anagrams of the target. Compare sorting each word with counting letters, and discuss case and non-letter…
    Last asked Aug 2026
  • Capacity to ship packages within D daysCodingPackages stand in a line with known weights and must be shipped in that order, one trip a day, by a ship with a fixed weight capacity. Return the smallest capacity that ships…
    Last asked Aug 2026
  • Copy list with random pointerCodingEach node of a singly linked list has a next pointer and a random pointer that may point to any node in the list or to nothing. Return a deep copy of the list in which no pointer…
    Last asked Aug 2026
  • Palindrome linked list without modifying the listCodingDecide whether a singly linked list reads the same both ways. Do it without changing the list, or restore it exactly if you reverse part of it. Compare the stack approach with…
    Last asked Apr 2026
  • Spiral matrixCodingReturn all elements of an m x n matrix in spiral order: along the top row, down the right column, back along the bottom row, up the left column, then inward.
    Last asked Apr 2026
  • Typed task lock for mutually exclusive job typesCodingSome jobs on a shared accelerator pool must not run alongside jobs of a different kind. Each job runs on its own thread and has one of two types: "gen" or "score". Any number of…
    Last asked Mar 2026
  • Memory management in Python and JavaCodingExplain how Python and Java manage memory: reference counting and the cycle collector versus tracing garbage collection, generations, the stack and the heap, and what leaks still…
    Last asked Feb 2026
  • Authentication token manager with expiryCodingBuild a manager for tokens that live for a fixed time: generate(id, now), renew(id, now) which only works on a token that has not expired, and countunexpired(now). Discuss how…
    Last asked Feb 2026
  • Meeting rooms IICodingGiven meeting start and end times, return the fewest rooms needed so no two overlapping meetings share a room, with a min-heap of end times or by sweeping sorted starts and ends.
    Last asked Feb 2026
  • Remove duplicates in place from an unsorted arrayCodingRemove repeated values from an unsorted array in place, keeping the first occurrence of each and their order, and return the new length. Compare a hash set with sorting first, and…
    Last asked Feb 2026
  • Assemble objects from chunks of an async streamCodingReads from an asynchronous stream return arbitrary chunks of bytes, so one object can be split across reads and one read can hold several objects. Write code that buffers the…
    Last asked Feb 2026
  • Idempotent request handling with idempotency keysCodingImplement a request handler that uses client-supplied idempotency keys so that retrying the same request returns the original result instead of doing the work twice. Handle two…
    Last asked Feb 2026
  • Sliding puzzle: fewest moves to solve the 15-puzzleCodingGiven a 4x4 sliding puzzle with one blank, return the fewest moves to reach the solved board, or report that it cannot be solved. Discuss the solvability check, BFS versus A or…
    Last asked Feb 2026
  • Distance from every desk to its nearest bathroomCodingAn office floor plan is a grid of bathrooms, desks and open floor. For every desk, return how many steps (up, down, left, right) it takes to reach the closest bathroom. Expect…
    Last asked Feb 2026
  • Populate next pointers in a perfect binary treeCodingIn a perfect binary tree, set each node's next pointer to the node to its right on the same level, or null at the end of a level. Do it with O(1) extra space by walking each level…
    Last asked Feb 2026
  • Distance from every node to the cycleCodingA connected graph contains exactly one cycle. For every node, return its distance to the nearest node on the cycle. Find the cycle by trimming leaves, then run a multi-source BFS…
    Last asked Jan 2026
  • Rotate a 3x3 grid of digits by 180 degreesCodingRotate a 3x3 grid of digits by 180 degrees and return the result, in place if you can. Only the title of this report was public.
    Last asked Jan 2026
  • Validate a JSON-like stringCodingWrite a validator that decides whether a string is well-formed JSON-like text: balanced braces and brackets, quoted keys, commas and colons in the right places, valid values…
    Last asked Jan 2026
  • Redundant connection in a directed graphCodingA rooted tree had one extra directed edge added. Given the edge list, return the edge to remove so the rest is a rooted tree again, taking the last such edge in the input when…
    Last asked Jan 2026
  • Shortest subarray with at least k distinct valuesCodingYou are given an integer array arr and an integer k. Call a contiguous subarray good if it contains at least k different values. Return the length of the shortest good subarray…
    Last asked Nov 2025
  • Merge k sorted arraysCodingMerge several sorted arrays into one sorted array with a min-heap holding one element from each array. Give the O(N log k) cost and compare with pairwise merging.
    Last asked Oct 2025
  • Mutexes, memory alignment, polymorphism and idempotencyCodingA fully technical round of short questions: what a mutex guarantees and how to use one correctly, memory efficiency and why the compiler aligns and pads structures, how runtime…
    Last asked Oct 2025
  • Reverse nodes in k-groupCodingReverse a linked list in groups of k nodes, leaving a final group shorter than k as it is. Do it in place with O(1) extra space.
    Last asked Oct 2025
  • Subsets, with and without backtrackingCodingReturn every subset of a set of distinct numbers using backtracking, then write it again iteratively, without backtracking, by building subsets up or using bit masks. Reported in…
    Possibly retired
  • Count the words in a documentCodingGiven the text of a document, return how many words it contains. The real work is the definition: agree with the interviewer what counts as a word (is "it's" one word or two, what…
    Possibly retired
  • Assign node labels to maximize the total edge sumCodingYou are given an undirected graph with n nodes numbered 0 to n - 1 and a list edges, where edgesi = a, b is an edge between nodes a and b. Give every node a label so that the…
  • Build the longest spike from an arrayCodingA spike is a sequence of integers that strictly increases up to a single peak and then strictly decreases. The peak belongs to both parts, and either part may be empty, so a…
  • Compress an n-ary tree by promoting childrenCodingEach node of an n-ary tree holds a unique integer value and an ordered list of children. You are given the root and a list compressednodes of values. Implement compress(root…
  • Count distinct values in every sliding windowCodingGiven an integer array nums and a window size k, return a list with one entry per contiguous window of length k (there are len(nums) - k + 1 of them). Each entry is the number of…
  • Count recipes a pantry can coverCodingYou keep a pantry of ingredients, written as a string pantry. Each character is one unit of an ingredient, so "aab" holds two units of a and one unit of b. You also have a list of…
  • Count valid 24-hour times from four digitsCodingWrite a function countvalidtimes(a, b, c, d) that takes four digits (each an integer from 0 to 9). Arrange all four digits as HH:MM on a 24-hour clock, using each given digit…
  • Days when the whole team is freeCodingA team is planning an offsite over a window of numdays days, numbered from 1 to numdays. Each team member has entered busy blocks as triples (personid, startday, endday). Both…
  • Employee shift timeline tableCodingEach shift is given as name, start, end, with integer times and start <= end. A shift covers the half-open interval start, end). One employee may have several shifts, and they may…
  • Fewest coins that cover every amount up to a limitCodingYou are given a list of coin denominations (positive integers) and an integer maxamount. You may take any number of coins of each denomination. Choose a multiset of coins so that…
  • Finish times for round-robin tasksCodingA single worker processes a list of tasks. Task i needs arri hours of work in total. The tasks wait in a queue in index order. Each turn, the worker takes the task at the front…
  • First occurrence or floor index in a sorted arrayCodingYou are given an array nums of integers sorted in non-decreasing order. It may contain repeated values. You are also given an integer target. Implement searchfirstorfloor(nums…
  • Gift delivery scheduler with limited agentsCodingYou are planning gift deliveries to employees in an office. The workday runs from hour 9 to hour 17. You get: - intervals, a list of start, end pairs with integer hours. Employee…
  • Group duplicate records that share any propertyCodingYou are given a list of records. Each record has a unique integer ID and three properties, for example a name, an email and a phone number: Two records are duplicates when they…
  • Integer to English words, built up by rangeCodingWrite a function that spells out an integer in English words. The interviewer adds the ranges in parts, and later parts should reuse earlier ones, so design for extension from the…
  • Largest number by changing up to k digits to 5CodingYou are given a string s that holds a positive integer (digits only, no leading zero) and an integer k. In one operation you pick any digit of s that is not 5 and change it to 5…
  • Largest square from 1x1 and 2x2 tilesCodingYou have M small tiles of size 1×1 and N large tiles of size 2×2. Build the largest possible square: every cell of the square must be covered by exactly one tile, with no gaps, no…
  • Largest value shared by two BSTsCodingYou are given the roots of two binary search trees, a and b, holding integer values. Return the largest integer that appears in both trees. If the trees share no value, return -1…
  • Longest palindrome from equal-length wordsCodingYou are given a list of words. Every word has the same length k and uses lowercase letters. The list can contain duplicates. Pick some of the words (possibly none) and join them…
  • Longest proper prefix that is also a suffixCodingGiven a string s, return the length of the longest string that is both a proper prefix and a proper suffix of s. - A prefix is a run of characters at the start of s; a suffix is a…
  • Longest substring without three repeats in a rowCodingGiven a string s, return the length of the longest substring of s in which no character appears three or more times in a row. Call such a substring semi-alternating: runs of one…
  • Maximum tests in one activation windowCodingA shared test environment receives test cases over time. You are given an integer array arrivalTime, where each entry is the time one test case arrives. Several test cases can…
  • Merge two n-ary trees by child positionCodingImplement mergetrees(root1, root2). It takes the roots of two n-ary trees and returns the root of a new tree that merges them. Each node has an integer val and an ordered list…
  • Merge two sorted arrays into distinct valuesCodingTwo integer arrays, nums1 and nums2, are each sorted in non-decreasing order and may contain repeated values. Return one array, sorted in ascending order, that contains every…
  • Merge two sorted interval listsCodingImplement mergetwointervallists(a, b). Each argument is a list of intervals start, end with integer endpoints and start <= end. Each list is sorted by start, and no two intervals…
  • Minimum adjacent swaps to group red ballsCodingA row of balls is given as a string balls. Each character is 'R' (red) or 'W' (white). In one move you may swap two neighbouring balls. Return the minimum number of moves needed…
  • Minimum swaps to put evens before oddsCodingGiven an integer array nums of length n, you want every even value to come before every odd value. In one move you may swap the values at any two distinct indices. Return the…
  • Recent file tracker with date and insertion orderCodingImplement a FileStorageSystem class that records files and answers two kinds of listing queries. - storefile(file: str, date: str) - None records a file with its storage date…
  • Recent search history with a size limitCodingBuild the recent-searches list behind a search box. When the user focuses the box, it shows their most recent distinct searches, newest first. Every search the user runs is…
  • Root of the largest tree in a forestCodingYou are given a list relations. Each entry child, parent says that parent is the direct parent of child. Together the relations form a forest: there are no cycles, and every node…
  • Set an even-parity bit in a byte's MSBCodingBytes sent over a noisy link often carry a parity bit so the receiver can detect a flipped bit. In this scheme the parity bit is the most significant bit (bit 7, value 128) and…
  • Spell a word on a 5-column letter boardCodingA text-entry device shows the 26 lowercase letters on a board 5 columns wide, filled row by row. Letter c sits at row (ord(c) - ord('a')) // 5 and column (ord(c) - ord('a')) % 5:…
  • Window with the most copies of a target valueCodingImplement mosttargetwindow(nums, targetindex, windowsize). The target value is numstargetindex. Look at every contiguous subarray of nums with exactly windowsize elements. Return…