Top K frequent elementsCodingGiven an integer array and k, return the k values that occur most often. Order them by count, highest first; break ties by the smaller value.
Key-value cache with per-entry TTLCodingImplement an in-memory key-value cache where every write gives a key, a value and a time-to-live. Once an entry's time is up it must behave as if it was never written.
Top k values per key in a MapReduce jobCodingWrite the reduce side of a MapReduce job that finds the k largest values for every key. The mapper passes each (key, value) pair through unchanged, and the shuffle groups the…
Last asked Oct 2026
Maximum frequency stack: pop the most frequent valueCodingBuild a stack of integers whose pop removes the value that occurs most often in the stack right now. When several values tie for the highest count, it removes the one whose…
Last asked Oct 2026
Link object tracks across two perception systemsCodingTwo perception systems on a vehicle, A and B, track the objects around it independently. Each gives an object its own ID, so one physical object has one ID in A and a different…
Last asked Sep 2026
Insert, delete and get random in O(1) with duplicatesCodingDesign a collection of integers that allows duplicates and supports insert, remove and a random pick, each in average O(1) time. The random pick returns a value with probability…
Last asked Sep 2026
Build reporting trees from employee-manager pairsCodingYou get a list of reporting relationships. Each person is a positive integer id, and a pair [employee, manager] means the employee reports directly to that manager.
Is a vehicle ready to go after its maintenance events?CodingA vehicle may leave for its next trip only when all of its maintenance work is closed. Its log is a list of events in three parallel arrays: actions[i] is "open" (a task of that…
Last asked Sep 2026
Find timed-out RPC calls from start and end logsCodingA service writes one log record when a remote procedure call starts and another when it ends. Given the log in time order and a timeout, report every call that ran longer than…
Last asked Sep 2026
Largest rectangle from a point set, any orientationCodingYou get distinct points with integer coordinates. Choose four of them that are the corners of a rectangle and return the largest area such a rectangle can have.
Last asked Sep 2026
Streaming top-K frequent elements with O(1) updatesCodingElements arrive one at a time from an unbounded stream (for example item ids from an event log). Design a structure that can report, at any moment, the k elements seen most often…
Last asked Sep 2026
Binary tree vertical order traversalCodingReturn a binary tree's values column by column, from the leftmost column to the rightmost. The root is at column 0, row 0.
Per-key fixed-window cost limiterCodingBuild a rate limiter that meters cost instead of counting requests. Each key may spend at most limit cost units in each fixed window of window seconds.
Last asked Sep 2026
Clone graph: deep-copy a connected undirected graphCodingGiven one node of a connected undirected graph, return a deep copy of the whole graph: new node objects with the same values and the same edges, each neighbor list in the same…
Last asked Sep 2026
Predict the most frequent next word in constant timeCodingFrom a body of text, build a predictor that, given a word, returns the word that most often came right after it. Every prediction must take O(1) time.
Earliest pair with a target sumCodingGiven an array of integers and a target, find two different positions whose values add up to the target. If several pairs work, return the one whose second index is smallest…
Subarray sum equals kCodingCount the contiguous subarrays whose sum equals k. The array may contain negative numbers and zeros, so a sliding window doesn't work.
Last asked Aug 2026
Unique and most frequent keys in a recent time windowCodingEvents arrive in timestamp order, each with a string key. The structure keeps only the m most recent events; when a new event arrives and there are already m, the oldest is…
Count pairs of words with no letters in commonCodingGiven a list of lowercase strings, count the unordered pairs of positions (i, j) with i < j whose strings have no character in common. Equal strings at different positions count…
Last asked Jul 2026
Blocking cache where reads wait for a missing keyCodingBuild a keyed cache whose reads can wait. get(key) returns at once when the key is present; otherwise it blocks until some thread writes that key. put(key, value) stores or…
Last asked Jul 2026
Find every set in a hand of Set cardsCodingIn the card game Set, each card has four attributes (color, shape, number and shading), and each attribute takes one of three values, so a card is four integers, each 0, 1 or 2…
Last asked Jul 2026
Thread-safe tally counter with bounded memoryCodingBuild a tally service that many threads call at once. Each call records an event for a key at a timestamp, and queries ask how many events a key had in an inclusive time range.
Last asked Jul 2026
+2
Group anagrams: bucket words that share the same lettersCodingGiven a list of words, group the words that are anagrams of one another (the same letters, each the same number of times). Every input word appears in exactly one group, and…
Most common website visit patternCodingYou get three lists of the same length: usernamei visited websitei at timestampi. A pattern is a sequence of three websites. A user matches a pattern if they visited those three…
Last asked May 2026
Per-position feedback for a guess against a secret wordCodingScore a guess against a secret word, as in Wordle. Both words have the same length. For each position of the guess, return one mark: - G — the letter is in the secret at this…
Last asked May 2026
Merge two named treesCodingEach tree node is a dictionary with three keys: name (a string), value (an integer) and children (an ordered list of nodes). Given two such trees t1 and t2, build a new merged…
Last-click attribution of conversions to ad clicksCodingAn ad platform credits each conversion (a purchase, a sign-up) to the last ad the user clicked before converting. Implement the in-memory APIs that record clicks and, when a user…
Last asked May 2026
First unique number in a streamCodingNumbers arrive one at a time. At any moment you may be asked for the first number, in arrival order, that has so far appeared exactly once. Build a structure that handles both…
Last asked May 2026
+2
Insert, delete and get random in O(1)CodingDesign a set of integers that supports insert, remove and pick-a-random-element, each in average O(1) time. A random pick returns every element currently in the set with equal…
Last asked May 2026
Unique pairs with a target sumCodingGiven an array of integers and a target, return every distinct pair of values that sums to the target. A pair counts once however many times its values repeat. A value can pair…
Last asked May 2026
Count words in a text streamCodingWrite a class that receives text from a stream, one segment at a time, and keeps a running count of how often each word has appeared so far. Unless you agree on a different…
Last asked Apr 2026
Process login logs split across shardsCodingLogin records are split across several shards. Each shard holds (timestamp, userid) records sorted by timestamp, but the shards overlap in time. Combine them correctly and…
Last asked Apr 2026
Maximum sum of a subarray whose ends differ by kCodingGiven an integer array nums and an integer k, a contiguous subarray numsl..r is good when its first and last elements differ by exactly k: abs(numsl - numsr) == k. Return the…
Last asked Apr 2026
Build a binary tree from parent-child descriptionsCodingEach description is parent, child, isleft: child is the left child of parent when isleft is 1, the right child when it is 0. The descriptions together describe one binary tree…
Last asked Mar 2026
Is every 3+ letter piece of a string a dictionary word?CodingYou get a lowercase string s and a dictionary of valid English words. Check whether every piece of s of length 3 or more is acceptable, first as an exact word and then, in the…
Last asked Mar 2026
Message latency from send and receive logsCodingTwo machines exchange messages. One CSV log lists when machine A sent each message; another lists when machine B received each one. Both clocks are synchronized. A message is…
Last asked Mar 2026
Open the lock: fewest wheel turns that avoid dead endsCodingA combination lock has four wheels, each showing a digit 0–9. One move turns a single wheel one step up or down, and the wheels wrap (9 to 0, 0 to 9). Given a start, a target and…
Last asked Feb 2026
Manager and peer relationships with is_manager queriesCodingBuild an in-memory org chart that learns relationships between employees one statement at a time and answers whether one employee is above another. Statements and questions arrive…
Last asked Feb 2026
Office badge register that tracks worker hours and payCodingBuild a register for an office. Workers badge in and out; the register keeps their time in the office and works out their pay. It comes in levels; each level adds methods to the…
Last asked Feb 2026
Next-word predictor from bigram countsCodingBuild a next-word predictor from training sentences, each a list of words, for example "a", "b", "c", "a", "s", "d". Learn which words follow each word and how often, then predict…
Parse logs and count error codesCodingRead the lines of a log, pull out the error code from each line that has one, and count how often each code appears. Real logs are messy: some lines have no code, and some are…
Last asked Feb 2026
Dot product of two sparse vectorsCodingTwo vectors A and B have the same length n, which can be large (up to 10^5 or more), and most of their entries are zero. Store them compactly and compute their dot product, sum(Ai…
Last asked Feb 2026
LRU cache where each item counts by its quantityCodingImplement a variant of the LRU cache in which capacity limits the total quantity of the stored items, not their number. Each item carries a positive integer quantity; an item of…
Last asked Feb 2026
Feature flags across channels with inheritanceCodingBuild a feature flag store organized by channels. Each channel has an id, its own map of flag names to true or false, and zero or more parent channels. Looking up a flag on a…
Last asked Jan 2026
Top-k and bottom-k words in a list and in a streamCodingFind the most and least frequent words, first in a fixed list, then in a stream that never ends, then for words seen only once. - topbottomk(words: liststr, k: int) -…
Last asked Jan 2026
Logger that reports its top K messagesCodingBuild an in-memory logger. It receives messages with timestamps and, at any point, returns the k most frequent messages: over everything logged so far, and then over a given time…
Last asked Jan 2026
Recover the original array from its doubled shuffleCodingAn array original was turned into changed by appending, for every element x, the value 2 x, and then shuffling the result. Given changed, return original, or an empty list if…
Last asked Jan 2026
Set with constant-time insert, delete and get randomCodingDesign a set of unique integers that supports insert, delete and returning a random element, each in average O(1) time. A random element must be uniform over the elements…
Last asked Jan 2026
Two sum with the lexicographically smallest index pairCodingGiven an integer array and a target, return the pair of distinct indices i, j with i < j and numsi + numsj == target that is lexicographically smallest: the smallest i, and among…
Last asked Dec 2025
Best score from three books in different categoriesCodingA student's reading log is a list of (category, points) pairs, one per book read. Score the log: count at most three books, at most one book from any category, and return the…
Last asked Dec 2025
Top K most active users from chat logsCodingA chat log is a list of messages, each recorded as the id of the user who sent it. A user's activity is the number of messages they sent. Return the k most active users. Show at…
Last asked Dec 2025
Thread-safe job registry with expiryCodingBuild an in-memory registry of jobs that many threads read and write at the same time. Each job is registered with a time to live. A lookup must never return a job whose time has…
Last asked Nov 2025
Settle group trip expenses with the fewest transfersCodingFriends on a trip record shared expenses. Each expense names the payer, the amount in cents, and the payees who split it equally; the payer may be one of them. Return money…
Last asked Nov 2025
Contiguous array with equal 0s and 1sCodingGiven an array of 0s and 1s, return the length of the longest contiguous subarray that holds as many 0s as 1s. Unless you agree on a different interface with the interviewer…
Last asked Nov 2025
Move rows between tasks and sum each taskCodingEach task owns some rows, and every row has an id and an integer value. Process a list of operations that add, delete and move rows, and answer sum queries for a task as you go…
Group shifted strings by their letter-shift patternCodingTwo strings belong together when shifting every letter of one by the same amount, wrapping from z to a, gives the other. So "abc", "bcd" and "xyz" belong together, and so do "az"…
Last asked Sep 2025
Count subarrays with at least k equal pairsCodingYou get an integer array nums, where each value is a type of fruit, and an integer k. In a subarray, a fruit type forms a pair if it appears at least twice; each type counts as at…
Last asked Sep 2025
Counter class with add, count and removeCodingWrite a class that stores strings with the number of times each was added, and lets you look up and remove them. Unless you agree on a different interface with the interviewer…
Last asked Sep 2025
Validate checkout and return logsCodingA library logs every checkout and return as (timestamp, bookid, ischeckout), where ischeckout is True for a checkout and False for a return. Check that the log is consistent: for…
Last asked Sep 2025
Count user sessions from an activity logCodingA large log file has one event per line: timestamp,user,action, with ISO 8601 timestamps, in no particular order. A user's session is a run of their events where no gap between…
Last asked Sep 2025
Contains duplicate within distance KCodingGiven an integer array nums and an integer k, decide whether two equal values sit at most k positions apart. If they do, also return the smallest gap among all such pairs. Unless…
Last asked Aug 2025
Construct binary tree from inorder and postorder traversalCodingGiven the inorder and postorder traversals of a binary tree whose values are all distinct, rebuild the tree and return its root. Unless you agree on a different interface with the…
Last asked Aug 2025
Recommend accounts your followees followCodingA follow graph is given as a dictionary from each user to the list of people they follow. For a user U, recommend everyone followed by the people U follows, leaving out U and…
Last asked Aug 2025
Longest substring with at most k distinct charactersCodingGiven a string s and an integer k, return the length of the longest substring of s that contains at most k distinct characters. Unless you agree on a different interface with the…
Last asked Aug 2025
Most packages of at most two items with equal total costCodingYou have items with costs itemcosts. Make as many packages as you can, where each package holds one or two items, every package has the same total cost, and no item is used twice…
Last asked Aug 2025
LFU cache with constant-time get and putCodingImplement a least-frequently-used (LFU) cache with get and put in O(1) average time. When the cache is full, evict the key used least often; among ties, evict the least recently…
Last asked Jul 2025
Palindrome permutation: can the letters form a palindromeCodingGiven a string, decide whether some rearrangement of its characters reads the same forwards and backwards. Then, when one exists, build it: return the lexicographically smallest…
Last asked Jul 2025
Recommend movies watched by friends and friends of friendsCodingRecommend movies to a user from their social circle. Two helper calls are given: one returns a user's friends, the other the movies a user has watched. Return movie titles ordered…
Sparse canvas painting with undo and redoCodingBuild an unbounded pixel canvas that remembers its paint history. Painting sets one pixel's color, reading returns a pixel's current color, and undo and redo walk back and forth…
Last asked Sep 2023
Documents and layers: create, rename, move and removeCodingProcess a list of operations on documents and the layers inside them, then return the final state of every document. Layer IDs are unique across all documents. Each operation is a…