Coding question interview practice for software engineers
A fifty-five-minute live coding interview on a question from Coding Questions: you write Python in the editor beside the call and run its tests while you explain your thinking, and the interviewer reads your code, asks about it and hints when you are stuck.
About 55 minutes · Python in a browser editor, with tests you run · a collection of coding interview questions to choose from · each one solvable free in your browser first
How the interview runs
- Introductions and framing5 min
- Understanding the problem5 min
- Approach8 min
- Implementation20 min
- Testing and review9 min
- Follow-up3 min
- Their questions5 min
Our library of coding questions
Longest substring without repeating charactersMedium
Given a string, return the length of its longest substring that contains no repeated character.
Merge intervalsMedium
Given a list of [start, end] intervals in no particular order, merge every pair that overlaps and return the non-overlapping intervals sorted by start.
Group anagramsMedium
Given a list of lowercase strings, group together the strings that are anagrams of one another and return the list of groups.
Daily temperaturesMedium
Given a list of daily temperatures, return a list of the same length where each entry is how many days you must wait after that day for a strictly warmer temperature.
Top k frequent elementsMedium
Given a list of integers and a number k, return the k most frequent values.
Product of array except selfMedium
Given a list of integers, return a list where each position holds the product of every other element, without using division.
Biggest islandMedium
Given a rectangular grid of "L" (land) and "W" (water) cells, return the size of the largest island, where an island is a group of land cells connected horizontally or vertically, not diagonally.
Word ladderMedium
Given a start word, a target word and a dictionary of same-length lowercase words, return a shortest sequence from start to target where each step changes exactly one letter and every word after the start is in the dictionary.
LRU cacheMedium
Implement an LRUCache class with a fixed positive capacity and two operations.
Edit distanceMedium
Given two strings a and b, return the minimum number of single-character insertions, deletions and replacements needed to turn a into b.
Given a list of non-negative bar heights, each bar one unit wide, return the total units of water trapped between the bars after rain.
Given an array of integers, find the pair of adjacent elements that has the largest product and return that product.
You are given an array of strings
input_array.Biggest LossEasy
You are given a list
priceswhere prices[i] is the value of a stock on day i.Binary Tree Vertical Order TraversalMedium
You are given the root of a binary tree of integers.
Binary Wildcard CombinationsEasy
You are given a string
sconsisting only of the characters '0', '1', and '?'.Given an integer k (the number of bits), return every length-k binary string, ordered first by the number of set bits (ascending) and, within the same number of set bits, by numeric value (ascending).
Given a year, return the century it is in.
You are given an input string
textand anorderingstring made of distinct characters.Check PalindromeEasy
Given the string, check if it is a palindrome — i.e.
Collect Coins In MatrixMedium
There are N coins placed on a grid, each at an integer coordinate (x, y) with x >= 1 and y >= 1.
Combination SumMedium
You are given a list of distinct positive integers
candidatesand a positive integertarget.Count ABC StringsMedium
Given a length n, return how many strings of length n can be formed from the letters 'a', 'b' and 'c' subject to two rules: - the string contains at most one 'b', and - it never contains three or more consecutive 'c' (at most two in a row).
Count Palindromic SubstringsMedium
You are given a string
s.Count Unival SubtreesMedium
You are given the root of a tree in which every node holds a value and a list of children (a node may have any number of children; a node with no children is a leaf).
Implement an algorithm to delete a node from the middle of a singly linked list, given access ONLY to that node (you do not have the head of the list).
Divisor-Free Team SizeMedium
You are given an integer
n.Implement a Vector (Dynamic Array)Medium
Build a growable array on top of a fixed-size block of storage, the way
std::vector/ Python'slistwork under the hood.Evaluate Reverse Polish NotationMedium
You are given a list of strings
tokensrepresenting a valid arithmetic expression in Reverse Polish (postfix) notation.Fibonacci NumberEasy
The Fibonacci sequence starts with F(1) = 1 and F(2) = 1, and every later term is the sum of the two preceding ones: F(n) = F(n-1) + F(n-2).
Find AnagramsEasy
You are given a list of strings
words.Find Peak ElementMedium
A peak element is one that is strictly greater than both of its neighbours.
A product has versions numbered 1 to n.
Fit Words In GridMedium
You are given a list of
words, a number of rowsnum_rows, and a number of columnsnum_cols.Flooded WorldHard
The world is flooding.
Fruit Into BasketsMedium
You are walking down a row of fruit trees, given as a list
fruitswhere fruits[i] is the type of fruit growing on tree i.Good NumbersMedium
A number t is "good" if it can be written as the sum of two cubes in at least two distinct ways, i.e.
Breadth-First Search on an Adjacency ListEasy
A graph is given as an adjacency list: a dict mapping each node to the list of nodes it has an edge to.
Implement a Hash Table with Linear ProbingMedium
Build an open-addressing hash table over a fixed-size array of
mslots.Highlight Chemical SymbolsEasy
You are given a list of names
namesand a list ofsymbols.Implement Trie (Prefix Tree)Medium
A trie (prefix tree) stores strings so that lookups by whole word or by prefix run in time proportional to the query length.
Insertion SortEasy
Sort a list the way you would sort a hand of cards: walk left to right and, for each element, slide it back over the already-sorted prefix until it sits in the right place.
Isomorphic TreesMedium
Two binary trees are isomorphic if one can be obtained from the other by swapping the left and right children of any number of nodes (any nodes, at any levels).
JSON Path LookupMedium
You are given a nested JSON-like structure
root(composed of dicts and lists) and a dot-separatedpathstring.K Closest Points to OriginMedium
You are given a list
pointswhere points[i] = [x, y] is a point on the plane, and an integer k.KnapsackMedium
You are given a list of items, each a (value, weight) pair of positive integers, and a knapsack of integer capacity.
Kth Smallest ElementMedium
You are given an unsorted list of integers
numsand an integer k.Longest Common SubsequenceMedium
A subsequence of a string keeps characters in their original order but not necessarily contiguous ("ELO" is a subsequence of "HELLO").
Longest Consecutive SequenceMedium
You are given an unsorted list of integers
nums.Longest Increasing SubsequenceMedium
You are given an integer array
nums.You are given a string
s.Longest Repeating Character ReplacementMedium
You are given a string
sof uppercase English letters and an integerk.Longest Subarray With Sum At Most KMedium
You are given an array of positive integers
aand a non-negative integerk.Longest Word in DictionaryMedium
You are given a list of strings
words.You are given an array of distinct non-negative integers
statues, where each value is the size of a statue you own.Matrix Best PathHard
You are given an R x C matrix that contains each integer from 1 to R*C exactly once (all values are distinct).
Matrix Chain MultiplicationHard
Matrix multiplication is associative: A @ B @ C can be computed as (A @ B) @ C or A @ (B @ C) — the result is the same, but the amount of work is not.
You are given a matrix of integers
matrixwhere matrix[i][j] is the price of the room on floor i, column j of a hotel (row 0 is the top floor).Implement a Max-HeapMedium
Build a binary max-heap stored in a flat array.
You are given a list of non-negative integer weights arranged in a row (the vertices of a path graph).
Maximum Average Subarray IEasy
You are given a list of integers
numsand an integerk.Maximum SubarrayMedium
You are given an array of integers (which may be positive or negative).
Median Of Two Sorted Arrays Of Equal SizeHard
You are given two arrays
aandb, each sorted in non-decreasing order and each of the same length n.Meeting RoomsEasy
You are given a list
intervalswhere intervals[i] = [start, end] is a meeting running fromstart(inclusive) toend(exclusive), in no particular order.Merge M Sorted ArraysMedium
You are given a collection of arrays, each of which is already sorted in non-decreasing order.
Merge SortMedium
Sort a list with merge sort: split it in half, sort each half recursively, then merge the two sorted halves back together in linear time by repeatedly taking the smaller of the two front elements.
Min StackMedium
Design a stack that supports each of these operations in O(1) time: - push(value): push
valueonto the stack.Mining Base LocationMedium
You are given a rectangular map given as a list of equal-length strings, where each cell is one of: '#' - a mountain (impassable) '*' - a mining site ' ' - open space A rover moves one step up, down, left or right at a time and may never enter a mountain cell.
Museum Guard DistancesMedium
A museum is represented by a square matrix whose cells are one of: 'O' - open space 'G' - a guard 'W' - a wall You are given the matrix.
Non-overlapping IntervalsMedium
You are given a list of intervals, each a pair [start, end) with start < end.
Number of ProvincesMedium
You are given the adjacency matrix of an undirected graph on
nnodes, encoded as a list ofnstrings each of lengthn.Peak Traffic TimeMedium
A server log records one session per user visit as a pair (start, end): the session is active from time
start(inclusive) up toend(exclusive).Points In TriangleMedium
You are given a triangle in the plane, described by its three vertices (x1, y1), (x2, y2) and (x3, y3), and two query points P = (p1, q1) and Q = (p2, q2).
Implement a Queue with a Fixed-Size Circular BufferEasy
Implement a FIFO queue on top of a fixed-size array (a ring buffer).
Implement a FIFO queue using only two stacks.
QuicksortMedium
Sort a list in place with quicksort: pick a pivot, partition the range so that everything smaller than the pivot ends up on its left and everything larger on its right, then recurse into the two sides.
Range Sum Query - ImmutableEasy
Design a structure over a fixed list of integers that answers range-sum queries.
Remove Common PhrasesMedium
You are given a list of sentences; each sentence is a string of lower-case words separated by single spaces.
Remove Duplicates From Unsorted Linked ListEasy
You are given the head node of an unsorted singly linked list.
Restore Set From Pair SumsHard
There was a collection X of N numbers (N >= 3, duplicates allowed).
You are given the head node of a singly linked list.
Rod CuttingMedium
You have a rod of integer length n and a price list: prices[i] is the selling price of a rod piece of length i (prices[0] is 0 and unused).
Shell TokenizerEasy
You are given a command string like the ones typed into a shell.
Implement a Singly Linked ListMedium
Build a singly linked list from scratch, keeping both a head and a tail pointer plus a cached element count so size(), push_back() and back() are all O(1).
Spiral MatrixMedium
You are given an integer n.
You are given a list of integers
numssorted in non-decreasing order.You are given an array
arrof positive integers and a positive integertarget.Sum Root To Leaf NumbersMedium
You are given the root of a binary tree in which every node holds a single digit (0-9).
Target ExpressionMedium
You are given a list of single digits (each 0-9) and an integer target.
Task Cooldown TimeMedium
You are given a list of tasks
tasksthat must be executed in the given order, and a cooldownk.You are given a list of words and a page width.
Three Array Target SumMedium
You are given three integer arrays
a,b,cand an integertarget.Three SumMedium
You are given an array of integers
numsand an integertarget.Three Sum (Triplets to Zero)Medium
You are given a list of integers
nums.Union-Find with Union by Rank and Path CompressionMedium
Implement a disjoint-set (union-find) structure over the integers 0, 1, ..., n-1.
Valid BracesEasy
You are given a string
scontaining only the bracket characters '(', ')', '[', ']', '{' and '}'.Word SearchMedium
You are given a rectangular
gridof letters and aword.Word WrapEasy
You are given a message
textmade of words separated by single spaces, and a positive integerwidth.