Mock technical interviews with an AI interviewer.
Every problem leaves something out. Ask about it before you code.
Problems
- Balanced BracketsGiven a string, return whether its brackets are balanced: every opening bracket is closed, and brackets close in the reverse of the order they opened.EasyLists/stacks/queuesLists/stacks/queues
- Best Day to Buy and SellYou are given the price of a stock on each day, in order. Return the largest profit you could make from one purchase and one sale.EasyArrays & hashingArrays & hashing
- Breadth-First Visit OrderThere are n nodes numbered 0 to n - 1 and a list of connections between pairs of nodes. Return the order in which a breadth-first search starting at the start node visits the nodes it can reach.EasyGraphsGraphs
- Busiest NodeThere are n nodes numbered 0 to n - 1 and a list of connections, each a pair of nodes. Return the node that has the most connections.EasyGraphsGraphs
- Edge List to Adjacency ListsA graph has n nodes numbered 0 to n - 1 and a list of connections, each a pair of nodes joined both ways. Return its adjacency lists: for each node, in order, the list of its neighbors in increasing order.EasyGraphsGraphs
- Edge List to Adjacency MatrixA graph has n nodes numbered 0 to n - 1 and a list of edges, each written [u, v, w]. Return its adjacency matrix: an n by n grid with one cell for each ordered pair of nodes (row u, column v), and 0 where there is no edge.EasyGraphsGraphs
- Find a Value in a Sorted ArrayGiven an array of integers sorted in ascending order and a target value, return the index of the target in the array.EasyAlgorithm analysisAlgorithm analysis
- First Lone CharacterGiven a string, return the index of the first character that appears exactly once in it.EasySets & mapsSets & maps
- First Odd ValueGiven a list of integers, find the first odd number in it and return that number.EasyArrays & hashingArrays & hashing
- Height of a Binary TreeGiven the root of a binary tree, return its height: the number of edges on the longest path from the root down to a leaf.EasyTreesTrees
- Hub of a NetworkOne hub node is joined directly to every other node, and there are no other connections. Given the connections, each a pair of nodes, return the hub.EasyGraphsGraphs
- Insert a Value Into a Search TreeGiven the root of a binary search tree and a value, insert the value as a new leaf and return the root of the tree.EasyTreesTrees
- Insert Into a Min-HeapAn array holds a binary min-heap. Insert a new value into the heap in place: the function returns nothing, and the examples show the array afterwards.EasyHeapsHeaps
- Is It a Simple GraphA graph has n nodes numbered 0 to n - 1 and a list of edges, each a pair of nodes. A simple graph has no edge from a node to itself and no edge listed twice. Return whether this graph is simple.EasyGraphsGraphs
- Is It a Valid PathA graph has n nodes numbered 0 to n - 1 and a list of connections. Given a sequence of nodes, return whether it is a valid path through the graph: each node in the sequence must be connected to the next one.EasyGraphsGraphs
- Is the Array a Max-Heap?An array of integers is supposed to store a binary max-heap. Return whether it really is one.EasyHeapsHeaps
- Is the Array a Min-Heap?Given an array of integers, return whether it is a valid binary min-heap.EasyHeapsHeaps
- Is There a RouteThere are n nodes numbered 0 to n - 1 and a list of connections, each a pair of nodes. Decide whether the target node can be reached from the source node by following connections.EasyGraphsGraphs
- Merge Two Sorted Linked ListsYou are given the heads of two linked lists, each sorted in ascending order. Merge them into a single sorted list and return its head.EasyLists/stacks/queuesLists/stacks/queues
- Most Frequent WordGiven a list of words, return the word that appears most often.EasyArrays & hashingArrays & hashing
- Pair That Reaches the TargetGiven a list of integers and a target, find two entries that sum to the target and return their positions, smaller position first.EasySets & mapsSets & maps
- Palindrome in a Linked ListGiven the head of a singly linked list, return whether the list is a palindrome: its values read the same from head to tail as from tail to head.EasyLists/stacks/queuesLists/stacks/queues
- Rearranged WordsGiven two words, return true if the second can be made by rearranging the letters of the first.EasySets & mapsSets & maps
- Remove Matching Nodes From ListGiven the head of a singly linked list and an integer, remove the node holding that integer and return the head of the resulting list.EasyLists/stacks/queuesLists/stacks/queues
- Repeat Within K PositionsGiven a list of integers and a number k, say whether some value appears twice within k positions of each other.EasySets & mapsSets & maps
- Reverse a Linked ListGiven the head of a singly linked list, reverse the list and return the head of the reversed list.EasyLists/stacks/queuesLists/stacks/queues
- Separate NetworksA company has n computers numbered 0 to n - 1, and a list of cables, each joining two computers. Computers that can reach each other through cables are on the same network. How many separate networks are there?EasyGraphsGraphs
- The Person Everyone TrustsAmong n people numbered 1 to n, you get pairs [a, b] meaning a trusts b. Return the number of the person whom all the others trust and who trusts no one, or -1 if nobody fits.EasyGraphsGraphs
- Tree Traversal By NameGiven a binary tree and the name of a depth-first traversal, return the node values in the order that traversal visits them.EasyTreesTrees
- Tree Values Level by LevelGiven the root of a binary tree, return its values level by level: one list for each level, from the root's level down, each level from left to right.EasyTreesTrees
- Values in Both ListsGiven two arrays of integers, return the values that appear in both, in any order.EasySets & mapsSets & maps
- Word List Follows a PatternGiven a pattern of letters and a list of words, return true if the words follow the pattern: the i-th letter of the pattern stands for the i-th word.EasySets & mapsSets & maps
- Cheapest Network From a Start ServerA network grows from a start server. There are n servers numbered 0 to n - 1 and a list of cables that could be laid, each [u, v, cost]. Each step, the network lays the cheapest cable that brings in a server it does not have yet. Return the servers in the order they join, starting with the start server.MediumGraph algorithmsGraph algorithms
- Cheapest Roads to Connect Every TownThere are n towns numbered 0 to n - 1 and a list of roads that could be built, each [u, v, cost], working both ways once built. Return the smallest total cost of roads to build so that every town can reach every other.MediumGraph algorithmsGraph algorithms
- Count Land PatchesYou are given a grid of 0s and 1s, where 1 is land and 0 is water. Return how many separate patches of land the grid contains.MediumGraphsGraphs
- Count Subarrays Summing to KGiven a list of integers and a target k, return the number of subarrays whose elements add up to k.MediumArrays & hashingArrays & hashing
- Delete a Key From a Search TreeGiven the root of a binary search tree and a key, delete the node that holds the key and return the root of the tree.MediumTreesTrees
- Depth-First Visit OrderThere are n nodes numbered 0 to n - 1, joined by two-way connections. Return the order in which a depth-first search from the start node visits the nodes: it always goes as deep as it can before backing up.MediumGraphsGraphs
- Distance to the Nearest MineA grid has open cells (0), walls (1) and mines (2). For every cell, return the fewest steps from it to the nearest mine, moving between open cells. A mine is 0 steps from a mine.MediumGraphsGraphs
- Does the Graph Have a CycleA graph has n nodes numbered 0 to n - 1 and a list of connections, each joining two nodes both ways. Return whether the graph has a cycle: a way to leave a node and come back to it without using any connection twice.MediumGraph algorithmsGraph algorithms
- Evaluate a Postfix ExpressionGiven the tokens of an arithmetic expression in postfix (reverse Polish) notation, evaluate it and return the result. The operators are +, -, * and /.MediumLists/stacks/queuesLists/stacks/queues
- Fewest Steps Through a MazeA maze is a grid in which 0 is an open cell and 1 is a wall. Starting at the top-left cell, find the fewest steps needed to reach the bottom-right cell.MediumGraphsGraphs
- Finish Every TaskThere are n tasks numbered 0 to n - 1. Some tasks must be finished before others, given as a list of pairs [a, b], meaning a must be finished before b. Can all the tasks be finished?MediumGraphsGraphs
- Inorder Without RecursionGiven the root of a binary tree, return its values in inorder (the left subtree, then the node, then the right subtree) without using recursion.MediumTreesTrees
- Is It a Search Tree?Given the root of a binary tree, return whether it is a valid binary search tree.MediumTreesTrees
- Kth Largest With a HeapGiven an array of integers and an integer k, return the kth largest element, where k = 1 means the largest.MediumHeapsHeaps
- Kth Smallest in a Search TreeGiven the root of a binary search tree and an integer k, return the kth smallest value in the tree, where k = 1 means the smallest.MediumTreesTrees
- Longest Streak of NeighborsGiven an array of integers, return the length of the longest streak of values that follow one another by exactly 1 (such as 7, 8, 9), wherever those values sit in the array.MediumSets & mapsSets & maps
- Merge Overlapping IntervalsYou are given a list of intervals, each written as a pair [start, end]. Merge the intervals that overlap and return the result.MediumArrays & hashingArrays & hashing
- Order the TasksThere are n tasks numbered 0 to n - 1 and a list of rules [a, b], each meaning task a must be done before task b. Return an order in which to do all the tasks that keeps every rule.MediumGraph algorithmsGraph algorithms
- Peak of a Mountain ArrayAn array of integers strictly increases up to its peak and strictly decreases after it. Return the index of the peak.MediumAlgorithm analysisAlgorithm analysis
- Product of All Other ElementsGiven a list of integers, return a list of the same length in which each position holds the product of all the other elements. Do not use division.MediumArrays & hashingArrays & hashing
- Remove the Minimum From a HeapAn array holds a binary min-heap, with the root at index 0 and the children of index i at 2i + 1 and 2i + 2. Remove the smallest value from the heap in place: the function returns nothing, and the examples show the array that remains.MediumHeapsHeaps
- Remove the Nth Node From the EndGiven the head of a linked list and a positive integer n, remove the nth node from the end of the list and return the head.MediumLists/stacks/queuesLists/stacks/queues
- Shortest Distances From a SourceA graph has n nodes numbered 0 to n - 1 and a list of edges [u, v, w], each with a cost w of at least 0. Return the cheapest total cost from the source to every node, or -1 for a node the source cannot reach.MediumGraph algorithmsGraph algorithms
- Top K Values by CountGiven a list of integers and a number k, which k values occur most often?MediumSets & mapsSets & maps
- Morphing One Word Into AnotherTurn the begin word into the end word by changing one letter at a time; each word along the way must come from the given list. Return the fewest changes needed.HardGraphsGraphs
- Shortest Distances With Negative EdgesA graph has n nodes and a list of edges [u, v, w], where a cost w can be negative. Return the cheapest total cost from the source to every node, or an empty list if a cycle of negative total cost makes costs keep falling forever.HardGraph algorithmsGraph algorithms
- Shortest Stretch Holding All LettersFind the shortest stretch of s holding all the letters of t, with as many copies of each letter as t has.HardSets & mapsSets & maps