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,426–4,450
Maintain an infinite set of positive integers that supports popSmallest(), which removes and returns the current smallest element, and addBack(num), which re-inserts a number…
General practice
Find the smallest integer x ≥ n whose binary representation is all 1s (i.e., x = 2^k − 1 for some k). In other words…
General practice
Given an integer product, find the smallest positive integer whose decimal digits multiply to that product (or return -1 if no such number exists); the…
General practice
Companies: Nagarro
Array · Counting · Hash Table
Given a palindromic lowercase string s, return the lexicographically smallest palindromic permutation of its letters. This reduces to counting character frequencies and…
General practice
Given a palindromic string s and integer k, return the k-th lexicographically smallest distinct palindromic permutation of s (or "" if fewer than k exist)…
General practice
Given an array nums and integer k, you may add any value in [-k, k] to each element at most once; find the minimum possible…
General practice
Given an integer array and k, choose for each element either +k or -k to minimize the final difference between the maximum and minimum elements…
General practice
Find the smallest rotation k of nums that maximizes the number of positions where the rotated value is <= its index. With n up to…
General practice
Companies: Bloomberg, Google, Microsoft
Array · Prefix Sum
Given a binary tree whose node values 0–25 map to letters 'a'–'z', return the lexicographically smallest string formed by the characters along any path from…
General practice
Given n and k, construct the lexicographically smallest lowercase string of length n whose characters' 1..26 numeric values sum to k (feasible since n ≤…
General practice
For each fixed-size sliding window in an array, determine the length of the smallest contiguous subarray that must be sorted so the whole window becomes…
General practice
For each index i, find the smallest subarray starting at i whose bitwise OR equals the maximum OR achievable from i to the end. The…
General practice
Return the lexicographically smallest subsequence of s that contains every distinct character exactly once while preserving relative order. The core challenge is choosing which…
General practice
Given a binary string and up to numOps bit flips, minimize the length of the longest contiguous block of identical characters after at most numOps…
General practice
Given a binary string s and up to numOps bit flips, find the smallest possible length of the longest contiguous block of identical characters after…
General practice
Given a binary tree, return the root of the smallest subtree that contains all nodes at the maximum depth (i.e., the lowest common ancestor of…
General practice
Given up to 16 required skills and up to 60 people each with some skills, find the smallest set of people whose combined skills cover…
Companies: Airbnb
Array · Bit Manipulation · Bitmask · Dynamic Programming
Repeatedly replace n with the sum of its prime factors (counting multiplicity) until it no longer changes, and return the smallest value reached. The core…
General practice
Rearrange the digits of an integer to produce the smallest possible numeric value without changing its sign and without any leading zeros. For positive numbers…
General practice
Reshape a 1D array into a rowsCount x colsCount matrix filled column-by-column in a "snail" (vertical snake) pattern—first column top-to-bottom, next bottom-to-top…
General practice
Simulate the snake moving on an n×n grid (cells labeled row-major as i*n + j) starting at cell 0, applying the sequence of UP/RIGHT/DOWN/LEFT commands…
General practice