Coding interview problems

Practice 48 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 / 48 solved

48 problems

Two Sum

easy

Two Sum: finding two numbers in an array that add up to a given target number

arrays
hashmap

Merge Intervals

medium

Given a collection of intervals, merge any overlapping intervals.

arrays
sorting

Reverse a String

easy

reverse a string interview question

strings

Longest Common Prefix

easy

Find the longest common prefix string amongst an array of strings.

strings

Palindrome String

easy

Palindrome String: Free. No login required. Python technical interview question

strings
two-pointers

Palindromic Substrings

medium

Count how many substrings of a string are palindromes.

strings
dynamic-programming

Longest Palindromic Substring

medium

Find the longest contiguous substring that is a palindrome.

strings
dynamic-programming

Palindrome Linked List

easy

Check whether the values of a singly linked list form a palindrome.

linked-list
two-pointers

Roman to Integer

easy

Given a Roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 to 3999.

strings
math

Letter Combinations of a Phone Number

medium

Write a function to generate all possible combinations of letters that can be formed from a given string of digits representing a phone number.

strings
backtracking

Valid Parentheses

easy

valid parentheses coding question

strings
stack

Find the Index of the First Occurrence in a String

easy

Learn how to find the index of the first occurrence of a substring in a string in this coding interview problem.

strings
two-pointers

Length of Last Word

easy

Find the length of the last word in a given string.

strings

Spiral Matrix

medium

given number n return matrix n by n with numbers in spiral order

arrays
matrix

FizzBuzz

easy

Classic FizzBuzz: return a list from 1 to n with Fizz/Buzz substitutions.

strings
math

Contains Duplicate

easy

Return true if any value appears at least twice in the array.

arrays
hashmap

Maximum Subarray

medium

Find the contiguous subarray with the largest sum and return that sum.

arrays
dynamic-programming

Fibonacci Number

easy

Return the nth Fibonacci number (0-indexed).

math
dynamic-programming

Factorial

easy

Compute n! (the factorial of a non-negative integer n).

math
recursion

Move Zeroes

easy

Move all zeroes to the end while keeping the order of non-zero elements.

arrays
two-pointers

Single Number

easy

Every element appears twice except one. Find the single one.

arrays
bit-manipulation

Best Time to Buy and Sell Stock

easy

Maximize profit from a single buy/sell of a stock given daily prices.

arrays
dynamic-programming

Valid Anagram

easy

Determine whether one string is an anagram of another.

strings
hashmap

Binary Search

easy

Return the index of target in a sorted array, or -1 if not present.

arrays
binary-search

Count Vowels

easy

Count the number of vowels in a string.

strings

Climbing Stairs

easy

Count distinct ways to climb n stairs taking 1 or 2 steps at a time.

math
dynamic-programming

Product of Array Except Self

medium

Return an array where each element is the product of all others.

arrays
prefix-sum

Trapping Rain Water

hard

Given an elevation map, compute how much water it can trap after raining.

arrays
two-pointers

Edit Distance

hard

Find the minimum number of edit operations to convert one word into another.

strings
dynamic-programming

Median of Two Sorted Arrays

hard

Find the median of two sorted arrays in logarithmic time.

arrays
binary-search

Longest Valid Parentheses

hard

Find the length of the longest valid well-formed parentheses substring.

strings
stack

Palindrome Number

easy

Determine whether an integer reads the same backward as forward.

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

FAQ

See also: