Medium

Problem

Pattern

Lists

Description

3Sum

Array, Two Pointers, Sorting

Blind 75, Grind 75, Grind 169, NeetCode 150, Google Top 50

Given an integer array nums, return all the triplets [nums[i], nums[j], nums[k]] such that i != j, i != k, and j != k,

Add Two Numbers

Linked List, Math, Recursion

Grind 169, NeetCode 150, Google Top 50

You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse

Binary Tree Level Order Traversal

Tree, Breadth-First Search, Binary Tree

Blind 75, Grind 75, Grind 169, NeetCode 150

Given the root of a binary tree, return the level order traversal of its nodes’ values. (i.e., from left to right,

Binary Tree Right Side View

Tree, Depth-First Search, Breadth-First Search, Binary Tree

Grind 75, Grind 169, NeetCode 150

Given the root of a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you

Binary Tree Zigzag Level Order Traversal

Tree, Breadth-First Search, Binary Tree

Grind 169

Given the root of a binary tree, return the zigzag level order traversal of its nodes’ values. (i.e., from left to

Bitwise And Of Numbers Range

Bit Manipulation

Given two integers left and right that represent the range [left, right], return the bitwise AND of all numbers in

Car Fleet

Array, Stack, Sorting, Monotonic Stack

NeetCode 150

There are n cars at given miles away from the starting mile 0, traveling to reach the mile target. You are given two

Cheapest Flights Within K Stops

Dynamic Programming, Depth-First Search, Breadth-First Search, Graph Theory, Heap (Priority Queue)

Grind 169, NeetCode 150

There are n cities connected by some number of flights. You are given an array flights where flights[i] = [from

Clone Graph

Hash Table, Depth-First Search, Breadth-First Search, Graph Theory

Blind 75, Grind 75, Grind 169, NeetCode 150

Given a reference of a node in a connected

Combination Sum

Array, Backtracking

Blind 75, Grind 75, Grind 169, NeetCode 150

Given an array of distinct integers candidates and a target integer target, return a list of all unique combinations of

Combination Sum II

Array, Backtracking

NeetCode 150

Given a collection of candidate numbers (candidates) and a target number (target), find all unique combinations in

Construct Binary Tree from Preorder and Inorder Traversal

Array, Hash Table, Divide and Conquer, Tree, Binary Tree

Blind 75, Grind 75, Grind 169, NeetCode 150

Given two integer arrays preorder and inorder where preorder is the preorder traversal of a binary tree and inorder is

Container With Most Water

Array, Two Pointers, Greedy

Blind 75, Grind 75, Grind 169, NeetCode 150

You are given an integer array height of length n. There are n vertical lines drawn such that the two endpoints of the

Copy List With Random Pointer

Hash Table, Linked List

NeetCode 150, Amazon Top 50

A linked list of length n is given such that each node contains an additional random pointer, which could point to any

Count And Say

String

The count-and-say sequence is a sequence of digit strings defined by the recursive formula: - countAndSay(1) = “1” -

Count Good Nodes in Binary Tree

Tree, Depth-First Search, Breadth-First Search, Binary Tree

NeetCode 150

Given a binary tree root, a node X in the tree is named good if in the path from root to X there are no nodes with a

Count Primes

Array, Math, Enumeration, Number Theory

Given an integer n, return the number of prime numbers that are strictly less than n

Course Schedule

Depth-First Search, Breadth-First Search, Graph Theory, Topological Sort

Blind 75, Grind 75, Grind 169, NeetCode 150, Amazon Top 50

There are a total of numCourses courses you have to take, labeled from 0 to numCourses - 1. You are given an array

Course Schedule II

Depth-First Search, Breadth-First Search, Graph Theory, Topological Sort

Grind 169, NeetCode 150, Google Top 50

There are a total of numCourses courses you have to take, labeled from 0 to numCourses - 1. You are given an array

Daily Temperatures

Array, Stack, Monotonic Stack

Grind 169, NeetCode 150

Given an array of integers temperatures represents the daily temperatures, return an array answer such that answer[i]

Decode Ways

String, Dynamic Programming

Blind 75, Grind 169, NeetCode 150

You have intercepted a secret message encoded as a string of numbers. The message is decoded via the following mapping:

Delete Node In A Linked List

Linked List

There is a singly-linked list head and we want to delete a node node in it. You are given the node to be deleted node

Design Add and Search Words

String, Depth-First Search, Design, Trie

Blind 75, Grind 169, NeetCode 150

Design a data structure that supports adding new words and finding if a string matches any previously added string

Divide Two Integers

Math, Bit Manipulation

Given two integers dividend and divisor, divide two integers without using multiplication, division, and mod operator

Edit Distance

String, Dynamic Programming

NeetCode 150

Given two strings word1 and word2, return the minimum number of operations required to convert word1 to word2. You

Encode and Decode Strings

Array, String, Design

Blind 75, Grind 169, NeetCode 150

Evaluate Reverse Polish Notation

Array, Math, Stack

Grind 75, Grind 169, NeetCode 150, Google Top 50

You are given an array of strings tokens that represents an arithmetic expression in a Reverse Polish Notation

Find First And Last Position Of Element In Sorted Array

Array, Binary Search

Given an array of integers nums sorted in non-decreasing order, find the starting and ending position of a given target

Find Minimum in Rotated Sorted Array

Array, Binary Search

Blind 75, Grind 169, NeetCode 150

Suppose an array of length n sorted in ascending order is rotated between 1 and n times. For example, the array nums =

Find the Duplicate Number

Array, Two Pointers, Binary Search, Bit Manipulation

Grind 169, NeetCode 150

Given an array of integers nums containing n + 1 integers where each integer is in the range [1, n] inclusive. There is

Game Of Life

Array, Matrix, Simulation

According to Wikipedia’s article <https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life>__: “The Game of Life, also

Gas Station

Array, Greedy

Grind 169, NeetCode 150

There are n gas stations along a circular route, where the amount of gas at the i :sup:th station is gas[i]. You

Generate Parentheses

String, Dynamic Programming, Backtracking

Grind 169, NeetCode 150

Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses

Group Anagrams

Array, Hash Table, String, Sorting

Blind 75, Grind 169, NeetCode 150, Amazon Top 50

Given an array of strings strs, group the anagrams together. You can return the answer in any order

H-Index

Array, Sorting, Counting Sort

Google Top 50

Given an array of integers citations where citations[i] is the number of citations a researcher received for their i

House Robber

Array, Dynamic Programming

Blind 75, Grind 169, NeetCode 150

You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed,

House Robber II

Array, Dynamic Programming

Blind 75, NeetCode 150, Google Top 50

You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed

Implement Trie (Prefix Tree)

Hash Table, String, Design, Trie

Blind 75, Grind 75, Grind 169, NeetCode 150, Google Top 50

A trie <https://en.wikipedia.org/wiki/Trie>__ (pronounced as “try”) or prefix tree is a tree data structure used to

Insert Delete GetRandom O(1)

Array, Hash Table, Math, Design, Randomized

Grind 169

Implement the RandomizedSet class: - RandomizedSet() Initializes the RandomizedSet object. - bool insert(int val)

Integer to Roman

Hash Table, Math, String

Seven different symbols represent Roman numerals with the following values: ====== ===== Symbol Value ====== ===== I

Jump Game

Array, Dynamic Programming, Greedy

Blind 75, Grind 169, NeetCode 150

You are given an integer array nums. You are initially positioned at the array’s first index, and each element in the

Koko Eating Bananas

Array, Binary Search

NeetCode 150

Koko loves to eat bananas. There are n piles of bananas, the i :sup:th pile has piles[i] bananas. The guards have

Kth Smallest Element in a BST

Tree, Depth-First Search, Binary Search Tree, Binary Tree

Blind 75, Grind 75, Grind 169, NeetCode 150

Given the root of a binary search tree, and an integer k, return the k :sup:th smallest value ( 1-indexed ) of

LRU Cache

Hash Table, Linked List, Design, Doubly-Linked List

Grind 75, Grind 169, NeetCode 150, Amazon Top 50, Google Top 50

Design a data structure that follows the constraints of a Least Recently Used (LRU) cache

Letter Combinations of a Phone Number

Hash Table, String, Backtracking

Grind 75, Grind 169, NeetCode 150

Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could

Longest Common Subsequence

String, Dynamic Programming

Blind 75, NeetCode 150

Given two strings text1 and text2, return the length of their longest common subsequence . If there is no common

Longest Consecutive Sequence

Array, Hash Table, Union-Find

Blind 75, Grind 169, NeetCode 150

Given an unsorted array of integers nums, return the length of the longest consecutive elements sequence. You must

Longest Palindromic Substring

Two Pointers, String, Dynamic Programming

Blind 75, Grind 75, Grind 169, NeetCode 150, Google Top 50

Given a string s, return the longest palindromic substring in s

Longest Substring Without Repeating Characters

Hash Table, String, Sliding Window

Blind 75, Grind 75, Grind 169, NeetCode 150, Google Top 50

Given a string s, find the length of the longest substring without duplicate characters

Lowest Common Ancestor of a BST

Tree, Depth-First Search, Binary Search Tree, Binary Tree

Blind 75, Grind 75, Grind 169, NeetCode 150

Given a binary search tree (BST), find the lowest common ancestor (LCA) node of two given nodes in the BST. According

Max Area of Island

Array, Depth-First Search, Breadth-First Search, Union-Find, Matrix

NeetCode 150, Google Top 50

You are given an m x n binary matrix grid. An island is a group of 1’s (representing land) connected 4-directionally

Maximum Product Subarray

Array, Dynamic Programming

Blind 75, Grind 169, NeetCode 150

Given an integer array nums, find a subarray that has the largest product, and return the product. The test cases are

Maximum Subarray

Array, Divide and Conquer, Dynamic Programming

Blind 75, Grind 75, Grind 169, NeetCode 150, Google Top 50

Given an integer array nums, find the subarray with the largest sum, and return its sum

Merge Intervals

Array, Sorting

Blind 75, Grind 75, Grind 169, NeetCode 150, Google Top 50

Given an array of intervals where intervals[i] = [start :sub:i , end :sub:i ], merge all overlapping intervals,

Min Cost to Connect All Points

Array, Union-Find, Graph Theory, Minimum Spanning Tree

NeetCode 150

You are given an array points representing integer coordinates of some points on a 2D-plane, where points[i] = [x

Min Stack

Stack, Design

Grind 75, Grind 169, NeetCode 150

Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. Implement the

Network Delay Time

Depth-First Search, Breadth-First Search, Graph Theory, Heap (Priority Queue), Shortest Path

NeetCode 150

You are given a network of n nodes, labeled from 1 to n. You are also given times, a list of travel times as directed

Number of Islands

Array, Depth-First Search, Breadth-First Search, Union-Find, Matrix

Blind 75, Grind 75, Grind 169, NeetCode 150, Amazon Top 50, Google Top 50

Given an m x n 2D binary grid grid which represents a map of ‘1’ s (land) and ‘0’ s (water), return the number of

Palindrome Partitioning

String, Dynamic Programming, Backtracking

NeetCode 150

Given a string s, partition s such that every substring of the partition is a palindrome. Return all possible

Palindromic Substrings

Two Pointers, String, Dynamic Programming

Blind 75, NeetCode 150

Given a string s, return the number of palindromic substrings in it. A string is a palindrome when it reads the same

Partition Equal Subset Sum

Array, Dynamic Programming

Grind 75, Grind 169, NeetCode 150

Given an integer array nums, return true if you can partition the array into two subsets such that the sum of the

Permutation in String

Hash Table, Two Pointers, String, Sliding Window

NeetCode 150

Given two strings s1 and s2, return true if s2 contains a permutation of s1, or false otherwise. In other words, return

Permutations

Array, Backtracking

Grind 75, Grind 169, NeetCode 150

Given an array nums of distinct integers, return all the possible permutations. You can return the answer in any order

Pow(x, n)

Math, Recursion

Grind 169, NeetCode 150

Implement pow(x, n) <http://www.cplusplus.com/reference/valarray/pow/>__, which calculates x raised to the power n

Product of Array Except Self

Array, Prefix Sum

Blind 75, Grind 75, Grind 169, NeetCode 150

Given an integer array nums, return an array answer such that answer[i] is equal to the product of all the elements

Remove Duplicates From Sorted Array Ii

Array, Two Pointers

Given an integer array nums sorted in non-decreasing order, remove some duplicates in-place

Remove Nth Node From End of List

Linked List, Two Pointers

Blind 75, Grind 169, NeetCode 150

Given the head of a linked list, remove the n :sup:th node from the end of the list and return its head

Reorder List

Linked List, Two Pointers, Stack, Recursion

Blind 75, Grind 169, NeetCode 150

You are given the head of a singly linked-list. The list can be represented as: :: L0 → L1 → … → Ln - 1 → Ln Reorder

Reverse Integer

Math

Grind 169, NeetCode 150

Given a signed 32-bit integer x, return x with its digits reversed. If reversing x causes the value to go outside the

Reverse Words In A String

Two Pointers, String

Given an input string s, reverse the order of the words. A word is defined as a sequence of non-space characters. The

Rotate Image

Array, Math, Matrix

Blind 75, Grind 169, NeetCode 150

You are given an n x n 2D matrix representing an image, rotate the image by 90 degrees (clockwise). You have to rotate

Rotting Oranges

Array, Breadth-First Search, Matrix

Grind 75, Grind 169, NeetCode 150, Amazon Top 50

You are given an m x n grid where each cell can have one of three values: - 0 representing an empty cell, - 1

Search a 2D Matrix

Array, Binary Search, Matrix

Grind 169, NeetCode 150

You are given an m x n integer matrix matrix with the following two properties: - Each row is sorted in non-decreasing

Search in Rotated Sorted Array

Array, Binary Search

Blind 75, Grind 75, Grind 169, NeetCode 150

There is an integer array nums sorted in ascending order (with distinct values). Prior to being passed to your

Set Matrix Zeroes

Array, Hash Table, Matrix

Blind 75, Grind 169, NeetCode 150

Given an m x n integer matrix matrix, if an element is 0, set its entire row and column to 0’s. You must do it in

Single Number Ii

Array, Bit Manipulation

Given an integer array nums where every element appears three times except for one, which appears exactly once. Find

Sort List

Linked List, Two Pointers, Divide and Conquer, Sorting, Merge Sort

Grind 169

Given the head of a linked list, return the list after sorting it in ascending order

String to Integer (atoi)

String

Grind 75, Grind 169

Implement the myAtoi(string s) function, which converts a string to a 32-bit signed integer. The algorithm for

Subsets

Array, Backtracking, Bit Manipulation

Grind 75, Grind 169, NeetCode 150

Given an integer array nums of unique elements, return all possible subsets (the power set). The solution set must

Subsets II

Array, Backtracking, Bit Manipulation

NeetCode 150

Given an integer array nums that may contain duplicates, return all possible subsets (the power set). The solution

Target Sum

Array, Dynamic Programming, Backtracking

NeetCode 150

You are given an integer array nums and an integer target. You want to build an expression out of nums by adding one of

Time Based Key-Value Store

Hash Table, String, Binary Search, Design

Grind 75, Grind 169, NeetCode 150

Design a time-based key-value data structure that can store multiple values for the same key at different time stamps

Top K Frequent Elements

Array, Hash Table, Divide and Conquer, Sorting, Heap (Priority Queue)

Blind 75, NeetCode 150, Google Top 50

Given an integer array nums and an integer k, return the k most frequent elements. You may return the answer in any

Tries

Trie

Two Sum II

Array, Two Pointers, Binary Search

NeetCode 150

Given a 1-indexed array of integers numbers that is already sorted in non-decreasing order, find two numbers such that

Unique Paths

Math, Dynamic Programming, Combinatorics

Blind 75, Grind 75, Grind 169, NeetCode 150, Google Top 50

There is a robot on an m x n grid. The robot is initially located at the top-left corner (i.e., grid[0][0]). The robot

Valid Sudoku

Array, Hash Table, Matrix

Grind 169, NeetCode 150

Determine if a 9 x 9 Sudoku board is valid. Only the filled cells need to be validated according to the following

Validate Binary Search Tree

Tree, Depth-First Search, Binary Search Tree, Binary Tree

Blind 75, Grind 75, Grind 169, NeetCode 150

Given the root of a binary tree, determine if it is a valid binary search tree (BST). A valid BST is defined as

Walls and Gates

Array, Breadth-First Search, Matrix

NeetCode 150

Word Break

Array, Hash Table, String, Dynamic Programming, Trie

Blind 75, Grind 75, Grind 169, NeetCode 150

Given a string s and a dictionary of strings wordDict, return true if s can be segmented into a space-separated

Word Search

Array, String, Backtracking, Depth-First Search, Matrix

Blind 75, Grind 75, Grind 169, NeetCode 150

Given an m x n grid of characters board and a string word, return true if word exists in the grid. The word can be

Zigzag Conversion

String

The string “PAYPALISHIRING” is written in a zigzag pattern on a given number of rows like this: (you may want to