Coding interview problems

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

Your progress

0 / 45 solved

45 problems

Two Sum

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

easy
Py
JS
arrays
hashmap

Merge Intervals

Given a collection of intervals, merge any overlapping intervals.

medium
Py
JS
arrays
sorting

Reverse a String

reverse a string interview question

easy
Py
JS
strings

Longest Common Prefix

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

easy
Py
JS
strings

Palindrome String

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

easy
Py
JS
strings
two-pointers

Roman to Integer

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

easy
Py
JS
strings
math

Letter Combinations of a Phone Number

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

medium
Py
JS
strings
backtracking

Valid Parentheses

valid parentheses coding question

easy
Py
JS
strings
stack

Find the Index of the First Occurrence in a String

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

easy
Py
JS
strings
two-pointers

Length of Last Word

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

easy
Py
JS
strings

Spiral Matrix

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

medium
Py
JS
arrays
matrix

FizzBuzz

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

easy
Py
JS
strings
math

Contains Duplicate

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

easy
Py
JS
arrays
hashmap

Maximum Subarray

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

medium
Py
JS
arrays
dynamic-programming

Fibonacci Number

Return the nth Fibonacci number (0-indexed).

easy
Py
JS
math
dynamic-programming

Factorial

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

easy
Py
JS
math
recursion

Move Zeroes

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

easy
Py
JS
arrays
two-pointers

Single Number

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

easy
Py
JS
arrays
bit-manipulation

Best Time to Buy and Sell Stock

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

easy
Py
JS
arrays
dynamic-programming

Valid Anagram

Determine whether one string is an anagram of another.

easy
Py
JS
strings
hashmap

Binary Search

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

easy
Py
JS
arrays
binary-search

Count Vowels

Count the number of vowels in a string.

easy
Py
JS
strings

Climbing Stairs

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

easy
Py
JS
math
dynamic-programming

Product of Array Except Self

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

medium
Py
JS
arrays
prefix-sum

Trapping Rain Water

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

hard
Py
JS
arrays
two-pointers

Edit Distance

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

hard
Py
JS
strings
dynamic-programming

Median of Two Sorted Arrays

Find the median of two sorted arrays in logarithmic time.

hard
Py
JS
arrays
binary-search

Longest Valid Parentheses

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

hard
Py
JS
strings
stack

Palindrome Number

Determine whether an integer reads the same backward as forward.

easy
Py
JS
math

Plus One

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

easy
Py
JS
arrays
math

Majority Element

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

easy
Py
JS
arrays
hashmap

Is Subsequence

Check whether one string is a subsequence of another.

easy
Py
JS
strings
two-pointers

First Unique Character in a String

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

easy
Py
JS
strings
hashmap

Search Insert Position

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

easy
Py
JS
arrays
binary-search

House Robber

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

medium
Py
JS
arrays
dynamic-programming

Jump Game

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

medium
Py
JS
arrays
greedy

Coin Change

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

medium
Py
JS
arrays
dynamic-programming

Longest Substring Without Repeating Characters

Find the length of the longest substring without repeating characters.

medium
Py
JS
strings
sliding-window

Container With Most Water

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

medium
Py
JS
arrays
two-pointers

Number of Islands

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

medium
Py
JS
matrix
graph

Word Break

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

hard
Py
JS
strings
dynamic-programming

Longest Increasing Subsequence

Find the length of the longest strictly increasing subsequence.

hard
Py
JS
arrays
dynamic-programming

Largest Rectangle in Histogram

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

hard
Py
JS
arrays
stack

Sliding Window Maximum

Return the maximum of every contiguous window of size k.

hard
Py
JS
arrays
sliding-window

Jump Game II

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

hard
Py
JS
arrays
greedy

FAQ

See also: