Interview questions
Find a company or topic. Read the sources, then practice.
Loading the question library…
Find a company or topic. Read the sources, then practice.
Loading the question library…
Showing 4,376–4,400
Given a binary string s and integer k, find the shortest substring that contains exactly k '1's and return the lexicographically smallest such substring (or…
General practice
Given a licensePlate string, find the shortest word in words that contains at least the same count of each alphabetic letter from licensePlate (case-insensitive, ignoring…
General practice
Given n nodes initially connected by the directed path 0→1→...→n-1, process incremental additions of forward edges (u→v with u<v) and after each addition report the…
General practice
Given n nodes with baseline directed edges i→i+1, process queries that add forward edges u→v and after each addition return the shortest path length from…
General practice
Given coordinates of points on a one-dimensional line, find the minimum absolute distance between any two points. This typically reduces to sorting the positions and…
General practice
Given coordinates of geometric entities in 2D, compute the minimal Euclidean distance between them. This is a computational-geometry problem that typically requires efficient…
General practice
For each index i in string s, compute the minimum absolute distance to the nearest occurrence of character c. This can be solved in linear…
General practice
Given an array of colored values and multiple queries (index, target color), return for each query the minimum absolute distance from the index to any…
General practice
Given a circular array of strings and a start index, return the minimum number of steps (moving left or right with wraparound) needed to reach…
General practice
Given a sequence of k-sided dice rolls, find the smallest length L such that some length-L sequence of faces cannot be formed as a (not-necessarily-contiguous)…
General practice
Given s and a pattern p containing exactly two '*' wildcards (each matching any sequence, including empty), find the length of the shortest substring of…
General practice
Given a string s, return the shortest palindrome obtainable by adding characters only to the front. This is equivalent to finding the longest palindromic prefix…
General practice
Maintain distances from root in a rooted weighted tree under two operations: update the weight of a single edge and query the shortest-path distance from…
General practice
Given a 2D grid with open cells, walls, a starting cell, and one or more food cells, find the minimum number of steps to reach…
General practice
Find the shortest distance from node 0 to every node in a directed graph whose edges are colored red or blue, with the constraint that…
General practice
General practice
Find the shortest string that contains three given strings as substrings, breaking ties by lexicographic order. The core challenge is to merge the strings using…
General practice
Given an array, remove the shortest contiguous subarray (possibly empty) so that the remaining elements — the concatenation of a prefix and a suffix —…
General practice
Find the length of the shortest non-empty contiguous subarray whose bitwise OR of all elements is at least k, or return -1 if no such…
General practice
Find the length of the shortest non-empty contiguous subarray whose bitwise OR is at least k (return -1 if none). With n up to 2e5…
General practice
Given a list of words and two target words (which may be the same), find the minimum index distance between any occurrence of the two…
General practice
Given a string s and an indices array that is a permutation of 0..n-1, reconstruct and return the string formed by moving the character at…
General practice
Given an array nums of length 2n structured as [x1,...,xn,y1,...,yn], return a new array that interleaves the two halves into [x1,y1,x2,y2,...,xn,yn].
Companies: Microsoft
Array
Determine the sign of the product of an integer array without computing it directly: return 0 if any element is zero, otherwise return 1 if…
General practice
Given a full 6-digit hex color like "#ABCDEF", find the closest "shorthand" color of the form "#XYZ" (which expands to "#XXYYZZ") by minimizing RGB distance…
General practice