Coding Interview Questions
The problems real companies actually ask — curated from the canon of NeetCode 150, Blind 75, LeetCode Top 100, CodeSignal and more. Read the problem, study the approach, then solve it in the editor and get an AI grade.
70 problems
Best Time to Buy and Sell Stock
easyGiven daily prices of a stock, find the maximum profit from a single buy followed by a later sell. If no profitable transaction exists, the profit is zero.
Binary Search
easyGiven a list of integers sorted ascending and a target, return the index of the target if present, otherwise negative one. The search must run in logarithmic time.
Climbing Stairs
easyYou are climbing a staircase that takes n steps to reach the top. Each move you may climb one or two steps. Count the number of distinct ways to reach the top.
Contains Duplicate
easyGiven a list of integers, decide whether any value appears more than once. Return true if at least one value is repeated, otherwise false.
Fizz Buzz
easyGiven a number n, return the sequence from one to n where multiples of three become Fizz, multiples of five become Buzz, multiples of both become FizzBuzz, and all other numbers stay as their string form.
Invert Binary Tree
easyGiven the root of a binary tree, produce its mirror image by swapping the left and right child of every node. Return the root of the inverted tree.
Linked List Cycle
easyGiven the head of a singly linked list, decide whether it contains a cycle, meaning some node's next pointer eventually revisits an earlier node. Use constant extra space.
Maximum Depth of Binary Tree
easyGiven the root of a binary tree, return its maximum depth, defined as the number of nodes along the longest path from the root down to a leaf.
Merge Two Sorted Lists
easyGiven the heads of two singly linked lists already sorted ascending, splice them into one sorted list and return its head. Reuse the existing nodes.
Reverse Linked List
easyGiven the head of a singly linked list, reverse the list in place and return the new head. The reversal should rewire the existing nodes rather than copying values.
Roman to Integer
easyGiven a Roman numeral string, convert it to its integer value. A smaller numeral placed before a larger one is subtracted rather than added.
Same Tree
easyGiven the roots of two binary trees, decide whether they are structurally identical and hold the same values at every position. Return true only if both shape and values match.
Two Sum
easyGiven a list of integers and a target value, find the two distinct positions whose values add up to the target. Return those two positions. Assume exactly one such pair exists.
Valid Anagram
easyGiven two strings, determine whether one is a rearrangement of the other. Two strings are anagrams when they contain exactly the same characters with the same frequencies.
Valid Palindrome
easyGiven a string, decide whether it reads the same forwards and backwards once you ignore case and consider only alphanumeric characters. Return true if it is such a palindrome.
Valid Parentheses
easyGiven a string of bracket characters drawn from round, square, and curly pairs, decide whether every opening bracket is closed by the correct type in the correct order. Return true if the string is well balanced.
3Sum
mediumGiven a list of integers, find every unique triple of values that sums to zero. Return the list of triples without duplicates.
Binary Tree Level Order Traversal
mediumGiven the root of a binary tree, return its node values grouped level by level from top to bottom, each level read left to right.
Clone Graph
mediumGiven a reference to a node in a connected undirected graph, return a deep copy of the whole graph. Each cloned node must hold the same value and a list of its cloned neighbours.
Coin Change
mediumGiven coin denominations and a target amount, return the fewest coins needed to make exactly that amount. If it cannot be made, return negative one. You have an unlimited supply of each coin.
Combination Sum
mediumGiven distinct positive candidates and a target, return all unique combinations that sum to the target. Each candidate may be used any number of times, and combinations differing only in order count once.
Container With Most Water
mediumGiven a list of non-negative heights, each representing a vertical line on a number line, find two lines that together with the x-axis hold the most water. Return that maximum area.
Course Schedule
mediumGiven a number of courses and a list of prerequisite pairs, decide whether you can finish all courses. You can finish them only if the prerequisite relationships contain no cycle.
Daily Temperatures
mediumGiven a list of daily temperatures, for each day return how many days you must wait until a warmer temperature. If no warmer day exists, the answer for that day is zero.
Encode and Decode Strings
mediumDesign an encoder that serializes a list of arbitrary strings into one string, and a decoder that recovers the original list. The strings may contain any characters, including your delimiters.
Evaluate Reverse Polish Notation
mediumGiven a list of tokens representing an arithmetic expression in postfix (Reverse Polish) notation, evaluate it. Operators are the four basic arithmetic operations and operands are integers.
Find Minimum in Rotated Sorted Array
mediumGiven an ascending array of unique values rotated at an unknown pivot, return the minimum element in logarithmic time.
Group Anagrams
mediumGiven a list of strings, cluster them so that words which are anagrams of each other land in the same group. Return the list of groups in any order.
House Robber
mediumGiven the amounts of money in a row of houses, find the maximum you can rob without taking from two adjacent houses, since adjacent robberies trigger the alarm.
Implement Trie (Prefix Tree)
mediumDesign a prefix tree supporting inserting a word, checking whether a full word exists, and checking whether any stored word starts with a given prefix.
Insert Interval
mediumGiven a list of non-overlapping intervals sorted by start and a new interval, insert it and merge any overlaps so the result stays sorted and non-overlapping.
Jump Game
mediumGiven a list where each value is the maximum forward jump from that position, decide whether you can reach the last index starting from the first.
Koko Eating Bananas
mediumGiven piles of bananas and a number of hours, find the smallest integer eating speed such that all piles are finished within the time. Each hour Koko eats from one pile up to her speed, finishing partial piles in that hour.
Kth Largest Element in an Array
mediumGiven a list of integers and a number k, return the kth largest element in sorted order, where duplicates count as distinct positions. Aim for better than a full sort.
Longest Consecutive Sequence
mediumGiven an unsorted list of integers, find the length of the longest run of consecutive values. The values do not need to be adjacent in the list. Aim for linear time.
Longest Increasing Subsequence
mediumGiven a list of integers, return the length of the longest strictly increasing subsequence. The chosen elements need not be contiguous but must keep their original order.
Longest Repeating Character Replacement
mediumGiven a string of uppercase letters and a budget k, find the length of the longest substring you can make all-identical by replacing at most k characters.
Longest Substring Without Repeating Characters
mediumGiven a string, find the length of the longest contiguous substring that contains no repeated character.
Lowest Common Ancestor of a BST
mediumGiven the root of a binary search tree and two of its nodes, return their lowest common ancestor, the deepest node that has both given nodes as descendants. A node may be a descendant of itself.
LRU Cache
mediumDesign a cache with a fixed capacity that supports get and put in constant time. When the cache is full and a new key is added, evict the least recently used entry. Reading or updating a key marks it most recently used.
Maximum Subarray
mediumGiven a list of integers, find the contiguous subarray with the largest sum and return that sum. The subarray must contain at least one element.
Merge Intervals
mediumGiven a list of intervals, merge every set of overlapping intervals and return the resulting non-overlapping intervals covering the same ranges.
Min Stack
mediumDesign a stack that supports push, pop, top, and retrieving the current minimum, with every operation running in constant time. The minimum must reflect only the values currently on the stack.
Non-overlapping Intervals
mediumGiven a list of intervals, return the minimum number you must remove so that the remaining intervals do not overlap.
Number of Islands
mediumGiven a grid of land and water cells, count the number of islands. An island is a group of land cells connected horizontally or vertically, and is surrounded by water or the grid edge.
Partition Equal Subset Sum
mediumGiven a list of positive integers, decide whether it can be split into two groups whose sums are equal.
Permutation in String
mediumGiven two strings, decide whether the second contains any contiguous substring that is a permutation of the first. Return true if such a window exists.
Permutations
mediumGiven a list of distinct integers, return every possible ordering of them. The list of permutations may be returned in any order.
Product of Array Except Self
mediumGiven a list of integers, return a new list where each position holds the product of every other value in the original list. Solve it without using division.
Remove Nth Node From End of List
mediumGiven the head of a singly linked list and a number n, remove the nth node counting from the end and return the head. Do it in a single pass.
Reorder List
mediumGiven a singly linked list, reorder it so it interleaves the first node, the last node, the second node, the second-to-last node, and so on. Rewire nodes in place without changing their values.
Rotate Image
mediumGiven an n by n matrix representing an image, rotate it ninety degrees clockwise in place without allocating another matrix.
Search in Rotated Sorted Array
mediumGiven an ascending array that has been rotated at an unknown pivot, find the index of a target value or return negative one. Achieve logarithmic time.
Subarray Sum Equals K
mediumGiven a list of integers and a target k, count how many contiguous subarrays sum to exactly k. Values may be negative.
Subsets
mediumGiven a list of distinct integers, return all possible subsets, including the empty set and the full set. The collection of subsets is the power set and may be returned in any order.
Top K Frequent Elements
mediumGiven a list of integers and a number k, return the k values that occur most frequently. The answer may be returned in any order, and the k most frequent values are guaranteed to be unambiguous.
Two Sum II Sorted Input
mediumGiven a list of integers already sorted in non-decreasing order and a target, return the one-based positions of the two values that add up to the target. Use constant extra space.
Unique Paths
mediumA robot starts at the top-left of an m by n grid and may move only right or down. Count the number of distinct paths it can take to reach the bottom-right corner.
Valid Sudoku
mediumGiven a partially filled 9x9 grid, decide whether the current placement is valid. Each row, each column, and each of the nine 3x3 sub-boxes must contain no repeated digit. Empty cells are ignored.
Validate Binary Search Tree
mediumGiven the root of a binary tree, decide whether it is a valid binary search tree, meaning every node's value is greater than all values in its left subtree and smaller than all in its right subtree.
Word Break
mediumGiven a string and a dictionary of words, decide whether the string can be segmented into a sequence of one or more dictionary words. Words may be reused.
Word Search
mediumGiven a grid of letters and a word, decide whether the word can be spelled by a path of adjacent cells moving horizontally or vertically. The same cell may not be reused within one path.
Edit Distance
hardGiven two strings, return the minimum number of single-character insertions, deletions, or substitutions needed to transform the first into the second.
Find Median from Data Stream
hardDesign a structure that accepts a stream of integers and can report the running median at any time. Support adding a number and querying the current median efficiently.
Median of Two Sorted Arrays
hardGiven two ascending sorted arrays, return the median of their combined ordering in logarithmic time relative to the smaller array.
Merge k Sorted Lists
hardGiven an array of k singly linked lists, each sorted ascending, merge them all into one sorted linked list and return its head.
Minimum Window Substring
hardGiven a string s and a pattern t, find the shortest contiguous substring of s that contains every character of t including duplicates. If none exists, return an empty string.
N-Queens
hardGiven a number n, place n queens on an n by n chessboard so that no two attack each other, and return all distinct board configurations. Queens attack along rows, columns, and both diagonals.
Trapping Rain Water
hardGiven a list of non-negative bar heights forming an elevation map, compute how many units of water are trapped after rain. Water sits in the dips between taller bars.
Word Ladder
hardGiven a start word, an end word, and a dictionary of equal-length words, find the length of the shortest transformation sequence that changes the start into the end, altering exactly one letter at a time and keeping every intermediate word in the dictionary. Return zero if impossible.