Medium
Problem |
Pattern |
Lists |
Description |
|---|---|---|---|
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, |
|
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 |
|
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, |
|
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 |
|
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 |
|
Bit Manipulation |
Given two integers left and right that represent the range [left, right], return the bitwise AND of all numbers in |
||
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 |
|
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 |
|
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 |
|
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 |
|
Array, Backtracking |
NeetCode 150 |
Given a collection of candidate numbers (candidates) and a target number (target), find all unique combinations in |
|
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 |
|
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 |
|
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 |
|
String |
The count-and-say sequence is a sequence of digit strings defined by the recursive formula: - countAndSay(1) = “1” - |
||
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 |
|
Array, Math, Enumeration, Number Theory |
Given an integer n, return the number of prime numbers that are strictly less than n |
||
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 |
|
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 |
|
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] |
|
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: |
|
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 |
||
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 |
|
Math, Bit Manipulation |
Given two integers dividend and divisor, divide two integers without using multiplication, division, and mod operator |
||
String, Dynamic Programming |
NeetCode 150 |
Given two strings word1 and word2, return the minimum number of operations required to convert word1 to word2. You |
|
Array, String, Design |
Blind 75, Grind 169, NeetCode 150 |
||
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 |
|
Array, Binary Search |
Given an array of integers nums sorted in non-decreasing order, find the starting and ending position of a given target |
||
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 = |
|
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 |
|
Array, Matrix, Simulation |
According to Wikipedia’s article <https://en.wikipedia.org/wiki/Conway%27s_Game_of_Life>__: “The Game of Life, also |
||
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 |
|
String, Dynamic Programming, Backtracking |
Grind 169, NeetCode 150 |
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses |
|
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 |
|
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 |
|
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, |
|
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 |
|
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 |
|
Array, Hash Table, Math, Design, Randomized |
Grind 169 |
Implement the RandomizedSet class: - RandomizedSet() Initializes the RandomizedSet object. - bool insert(int val) |
|
Hash Table, Math, String |
Seven different symbols represent Roman numerals with the following values: ====== ===== Symbol Value ====== ===== I |
||
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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, |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
Array, Two Pointers |
Given an integer array nums sorted in non-decreasing order, remove some duplicates in-place |
||
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 |
|
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 |
|
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 |
|
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 |
||
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 |
|
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 |
|
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 |
|
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 |
|
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 |
|
Array, Bit Manipulation |
Given an integer array nums where every element appears three times except for one, which appears exactly once. Find |
||
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 |
Grind 75, Grind 169 |
Implement the myAtoi(string s) function, which converts a string to a 32-bit signed integer. The algorithm for |
|
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 |
|
Array, Backtracking, Bit Manipulation |
NeetCode 150 |
Given an integer array nums that may contain duplicates, return all possible subsets (the power set). The solution |
|
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 |
|
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 |
|
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 |
|
Trie |
|||
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 |
|
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 |
|
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 |
|
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 |
|
Array, Breadth-First Search, Matrix |
NeetCode 150 |
||
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 |
|
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 |
|
String |
The string “PAYPALISHIRING” is written in a zigzag pattern on a given number of rows like this: (you may want to |