Coding interview problems

Practice 75 classic coding interview problems in Python, JavaScript, Java, Go, and Rust. Run your code against real test cases, then read the step-by-step solutions with time & space complexity.

Your progress

0 / 75 solved

Prefer a structured plan?

Follow the ordered Interview Roadmap: 0/75 solved.

Browse by pattern

75 problems

Two Sum

easy

Find the indices of two distinct values whose sum matches a target.

arrays
hashmap

Merge Intervals

medium

Sort and merge every overlapping or touching interval into a disjoint list.

arrays
sorting

Reverse a String

easy

Return a string with every character in reverse order without changing characters.

strings

Longest Common Prefix

easy

Find the longest leading substring shared by every string in a list.

strings

Palindrome String

easy

Determine whether a phrase reads the same after ignoring case and non-alphanumeric characters.

strings
two-pointers

Palindromic Substrings

medium

Count every contiguous substring that reads the same forward and backward.

strings
dynamic-programming

Longest Palindromic Substring

medium

Return the longest contiguous substring that is a palindrome.

strings
dynamic-programming

Palindrome Linked List

easy

Check whether the values represented by a singly linked list form a palindrome.

linked-list
two-pointers

Roman to Integer

easy

Convert a valid canonical Roman numeral into its integer value.

strings
math

Letter Combinations of a Phone Number

medium

Generate every letter combination represented by digits on a telephone keypad.

strings
backtracking

Valid Parentheses

easy

Validate that every bracket closes in the correct order and with the matching type.

strings
stack

Find the Index of the First Occurrence in a String

easy

Return the starting index of the first exact occurrence of one string inside another.

strings
two-pointers

Length of Last Word

easy

Measure the final whitespace-delimited word in a string.

strings

Spiral Matrix

medium

Generate an n-by-n matrix filled clockwise in spiral order.

arrays
matrix

FizzBuzz

easy

Produce the classic FizzBuzz sequence using divisibility rules.

strings
math

Contains Duplicate

easy

Determine whether any integer appears more than once in an array.

arrays
hashmap

Maximum Subarray

medium

Return the largest sum obtainable from a non-empty contiguous subarray.

arrays
dynamic-programming

Fibonacci Number

easy

Compute the zero-indexed Fibonacci number with an iterative recurrence.

math
dynamic-programming

Factorial

easy

Compute the product of all positive integers up to a non-negative input.

math
recursion

Move Zeroes

easy

Move every zero to the end while preserving non-zero element order.

arrays
two-pointers

Single Number

easy

Find the only value that is not paired using constant extra space.

arrays
bit-manipulation

Best Time to Buy and Sell Stock

easy

Find the best profit from one buy followed by one later sale.

arrays
dynamic-programming

Valid Anagram

easy

Check whether two lowercase strings contain identical character frequencies.

strings
hashmap

Binary Search

easy

Locate a target in a sorted unique array using logarithmic search.

arrays
binary-search

Count Vowels

easy

Count ASCII vowels in a string without changing other characters.

strings

Climbing Stairs

easy

Count ordered one-step and two-step paths to the top of a staircase.

math
dynamic-programming

Product of Array Except Self

medium

Build prefix and suffix products without division.

arrays
prefix-sum

Trapping Rain Water

hard

Compute water trapped between elevation bars after rainfall.

arrays
two-pointers

Edit Distance

hard

Measure the minimum insertions, deletions, and replacements between two strings.

strings
dynamic-programming

Median of Two Sorted Arrays

hard

Find the combined median without fully merging two sorted arrays.

arrays
binary-search

Longest Valid Parentheses

hard

Measure the longest contiguous substring of balanced parentheses.

strings
stack

Palindrome Number

easy

Determine whether a base-10 integer reads identically in reverse.

math

Plus One

easy

Add one to a number represented as an array of digits.

arrays
math

Majority Element

easy

Find the element that appears more than half the time in an array.

arrays
hashmap

Is Subsequence

easy

Check whether one string is a subsequence of another.

strings
two-pointers

First Unique Character in a String

easy

Find the index of the first non-repeating character in a string.

strings
hashmap

Search Insert Position

easy

Return the index where a target should be inserted into a sorted array.

arrays
binary-search

House Robber

medium

Maximize the loot from non-adjacent houses along a street.

arrays
dynamic-programming

Jump Game

medium

Decide whether you can reach the last index of an array of jump lengths.

arrays
greedy

Coin Change

medium

Find the fewest coins needed to make up a given amount.

arrays
dynamic-programming

Longest Substring Without Repeating Characters

medium

Find the length of the longest substring without repeating characters.

strings
sliding-window

Container With Most Water

medium

Find two lines that together with the x-axis hold the most water.

arrays
two-pointers

Number of Islands

medium

Count the number of islands in a grid of land and water cells.

matrix
graph

Word Break

hard

Determine whether a string can be segmented into words from a dictionary.

strings
dynamic-programming

Longest Increasing Subsequence

hard

Find the length of the longest strictly increasing subsequence.

arrays
dynamic-programming

Largest Rectangle in Histogram

hard

Find the area of the largest rectangle that fits under a histogram.

arrays
stack

Sliding Window Maximum

hard

Return the maximum of every contiguous window of size k.

arrays
sliding-window

Jump Game II

hard

Find the minimum number of jumps needed to reach the last index.

arrays
greedy

Reverse Linked List

easy

Reverse a singly linked list in place using real ListNode structures.

linked-list
pointers

Maximum Depth of Binary Tree

easy

Find the maximum depth of a binary tree using real TreeNode structures.

binary-tree
recursion

Course Schedule

medium

Determine whether all courses can be completed given prerequisite pairs.

graph
topological-sort

Rotting Oranges

medium

Find how many minutes are needed for rot to spread to every fresh orange.

matrix
graph

Redundant Connection

medium

Find the edge that creates a cycle in an otherwise tree-shaped graph.

graph
union-find

Kth Largest Element in an Array

medium

Return the kth largest value without requiring a fully sorted array.

arrays
heap

Top K Frequent Elements

medium

Return the k values that occur most often in an integer array.

arrays
hashmap

Subsets

medium

Generate every subset in the power set of a distinct integer array.

arrays
backtracking

Invert Binary Tree

easy

Swap every binary-tree node's left and right children.

binary-tree
depth-first-search

Same Tree

easy

Determine whether two binary trees have identical structure and values.

binary-tree
depth-first-search

Validate Binary Search Tree

medium

Check whether a binary tree satisfies strict BST ordering.

binary-tree
binary-search-tree

Binary Tree Level Order Traversal

medium

Return binary-tree values grouped by breadth-first level.

binary-tree
breadth-first-search

Lowest Common Ancestor of a BST

medium

Find the lowest shared ancestor of two values in a binary search tree.

binary-tree
binary-search-tree

Merge Two Sorted Lists

easy

Merge two sorted linked lists by rewiring their nodes.

linked-list
two-pointers

Linked List Cycle

easy

Detect a cycle from a linked list represented by next-node indices.

linked-list
two-pointers

Reorder List

medium

Reorder a linked list by alternating nodes from its front and back.

linked-list
two-pointers

Clone Graph

medium

Deep-copy a connected graph from its adjacency-list representation.

graph
depth-first-search

Pacific Atlantic Water Flow

medium

Find grid cells that can flow to both oceans under height constraints.

graph
matrix

Network Delay Time

medium

Compute how long a weighted directed network takes to receive a signal.

graph
shortest-path

Merge K Sorted Lists

hard

Merge k sorted sequences using a heap of current candidates.

linked-list
heap

Find Median from Data Stream

hard

Return the median after incrementally inserting every stream value.

heap
priority-queue

Permutations

medium

Generate every ordering of a distinct integer array.

arrays
backtracking

Combination Sum

medium

Find target-sum combinations when candidate values may be reused.

arrays
backtracking

Word Search

medium

Find a word by backtracking through adjacent grid cells.

matrix
backtracking

Implement Trie

medium

Execute insert, exact-search, and prefix-search operations on a trie.

trie
string

Design Add and Search Words

medium

Build a trie that supports exact letters and wildcard searches.

trie
backtracking

LRU Cache

medium

Simulate a bounded least-recently-used key-value cache.

hashmap
linked-list

FAQ