The Blind 75, visualized.
Step through every algorithm, compare four approaches from brute force to production grade, and rehearse the follow-up questions an interviewer will ask. 28 of 75 problems are live.
#1 · Arrays & Hashing
Two Sum
Given an array of integers and a target, return the indices of the two numbers that add up to the target. Exactly one solution exists and you may not use the same element twice.
#2 · Sliding Window
Longest Substring Without Repeating Characters
Given a string, find the length of the longest substring that contains no repeated character.
#3 · Trees
Invert Binary Tree
Given the root of a binary tree, invert it (swap every node's left and right children) and return its root.
#4 · Graphs
Course Schedule
There are n courses, and prerequisites[i] = [a, b] means you must take b before a. Return true if you can finish all courses, which is the same as asking whether the prerequisite graph has no cycle.
#5 · 1D DP
Coin Change
Given coin denominations and a target amount, return the fewest coins needed to make that amount, or −1 if it is impossible. Each coin can be used any number of times.
#6 · Arrays & Hashing
Contains Duplicate
Given an integer array, return true if any value appears at least twice, and false if every element is distinct.
#7 · Arrays & Hashing
Valid Anagram
Given two strings s and t, return true if t is an anagram of s: the same letters, each used exactly the same number of times, in any order.
#8 · Sliding Window
Best Time to Buy and Sell Stock
Given daily prices, choose one day to buy and a later day to sell to maximize profit. Return the maximum profit, or 0 if no profitable trade exists.
#9 · Arrays & Hashing
Product of Array Except Self
Return an array where out[i] is the product of every element of nums except nums[i], in O(n) time and without using division.
#10 · Arrays & Hashing
Group Anagrams
Given an array of strings, group the anagrams together. You may return the groups in any order.
#11 · Arrays & Hashing
Encode and Decode Strings
Design an algorithm to encode a list of strings into a single string, and decode it back to the original list. The strings can contain any characters, so no character is safe to use as a plain separator.
#12 · Arrays & Hashing
Longest Consecutive Sequence
Given an unsorted array of integers, return the length of the longest run of consecutive values (like 1, 2, 3, 4), regardless of their order in the array. The solution must run in O(n) time.
#13 · Two Pointers
Valid Palindrome
After lowercasing and removing every non-alphanumeric character, a phrase is a palindrome if it reads the same forwards and backwards. Given a string, return true if it is a palindrome.
#14 · Two Pointers
3Sum
Given an integer array, return all unique triplets [a, b, c] with a + b + c = 0. The solution set must not contain duplicate triplets.
#15 · Two Pointers
Container With Most Water
Given n vertical lines of given heights, pick two of them that together with the x-axis form a container holding the most water, and return that amount. (Area = distance between the lines × the shorter height.)
#16 · Sliding Window
Minimum Window Substring
Given strings s and t, return the shortest substring of s that contains every character of t (including duplicates). Return an empty string if no such window exists.
#17 · Sliding Window
Longest Repeating Character Replacement
Given a string of uppercase letters and an integer k, you may replace at most k characters with any letter. Return the length of the longest substring that can be turned into a single repeated letter.
#18 · Linked List
Reverse Linked List
Given the head of a singly linked list, reverse the list and return the new head.
#19 · Linked List
Merge Two Sorted Lists
Merge two sorted linked lists into one sorted list by splicing together the nodes of the two lists, and return its head.
#20 · Linked List
Reorder List
Rearrange L0 → L1 → … → Ln−1 → Ln into L0 → Ln → L1 → Ln−1 → L2 → … in place, without changing any node values.
#21 · Linked List
Remove Nth Node From End of List
Given the head of a linked list, remove the n-th node from the end of the list and return its head.
#22 · Linked List
Linked List Cycle
Given the head of a linked list, return true if the list contains a cycle: some node can be reached again by continuously following next.
#23 · Linked List
Merge k Sorted Lists
Given an array of k sorted linked lists, merge them into one sorted linked list and return its head.
#24 · Stack
Valid Parentheses
Given a string containing only '(', ')', '{', '}', '[' and ']', determine whether it is valid: every bracket is closed by the same type, in the correct order.
#25 · Binary Search
Find Minimum in Rotated Sorted Array
A sorted array of unique values was rotated an unknown number of times (for example [0,1,2,4,5,6,7] became [4,5,6,7,0,1,2]). Return its minimum element in O(log n) time.
#26 · Binary Search
Search in Rotated Sorted Array
A sorted array of distinct values was rotated at an unknown pivot. Given a target, return its index, or −1 if it is absent, in O(log n) time.
#27 · Heap / Priority Queue
Top K Frequent Elements
Given an integer array and an integer k, return the k most frequent elements, in any order. The algorithm should be better than O(n log n).
#28 · Heap / Priority Queue
Find Median from Data Stream
Design a data structure that supports addNum(num), which inserts an integer from a data stream, and findMedian(), which returns the median of everything inserted so far.