Problemset
499 problems3 difficulty levels67 topics
Pattern roadmap19 patterns, 138 problems, easiest idea first0/138 done
-
1Arrays & Hashing0/8
-
2Two Pointers0/5
-
3Sliding Window0/6
-
4Stack0/7
-
5Binary Search0/7
-
6Linked List0/10
-
7Trees0/14
- Invert Binary TreeEasy
- Maximum Depth of Binary TreeEasy
- Diameter of Binary TreeEasy
- Balanced Binary TreeEasy
- Same TreeEasy
- Subtree of Another TreeEasy
- Lowest Common Ancestor of a Binary Search TreeMedium
- Binary Tree Level Order TraversalMedium
- Binary Tree Right Side ViewMedium
- Count Good Nodes in Binary TreeMedium
- Validate Binary Search TreeMedium
- Kth Smallest Element in a BSTMedium
- Binary Tree Maximum Path SumHard
- Serialize and Deserialize Binary TreeHard
-
8Tries0/2
-
9Heap / Priority Queue0/4
-
10Backtracking0/9
-
11Graphs0/12
- Number of IslandsMedium
- Max Area of IslandMedium
- Walls and GatesMedium
- Rotting OrangesMedium
- Pacific Atlantic Water FlowMedium
- Surrounded RegionsMedium
- Course ScheduleMedium
- Course Schedule IIMedium
- Graph Valid TreeMedium
- Number of Connected Components in an Undirected GraphMedium
- Redundant ConnectionMedium
- Word LadderHard
-
12Advanced Graphs0/6
-
131-D Dynamic Programming0/10
-
142-D Dynamic Programming0/11
- Unique PathsMedium
- Longest Common SubsequenceMedium
- Best Time to Buy and Sell Stock with CooldownMedium
- Coin Change IIMedium
- Target SumMedium
- Interleaving StringMedium
- Longest Increasing Path in a MatrixHard
- Distinct SubsequencesHard
- Edit DistanceMedium
- Burst BalloonsHard
- Regular Expression MatchingHard
-
15Greedy0/8
-
16Intervals0/4
-
17Math & Geometry0/6
-
18Bit Manipulation0/7
-
19Bonus0/2
0 of 499 completed
499 results
- Contains Duplicate
Contains Duplicate (Easy): Given an integer array nums , return true if any value appears at least twice, and false if… Topics: Array, Hash Table, Sorting.
Easy - Valid Anagram
Valid Anagram (Easy): Given two strings s and t , return true if t is an anagram of s (same letters, same counts). Topics: String, Hash Table, Sorting.
Easy - Two Sum
Two Sum (Easy): Given an array of integers nums and an integer target , return the indices of the two numbers such that they add up… Topics: Array, Hash Table.
Easy - Group Anagrams
Group Anagrams (Medium): Given an array of strings strs , group the anagrams together. Return the groups in any order. Topics: Array, String, Hash Table.
Medium - Top K Frequent Elements
Top K Frequent Elements (Medium): Given an integer array nums and an integer k , return the k most frequent elements. On this… Topics: Array, Hash Table, Heap.
Medium - Product of Array Except Self
Product of Array Except Self (Medium): Given an integer array nums , return an array answer where answer[i] is the product of all… Topics: Array, Prefix Sum.
Medium - Valid Sudoku
Valid Sudoku (Medium): Determine if a 9 x 9 Sudoku board is valid. Only the filled cells need to be checked: each row, each… Topics: Array, Hash Table, Matrix.
Medium - Longest Consecutive Sequence
Longest Consecutive Sequence (Medium): Given an unsorted array nums , return the length of the longest run of… Topics: Array, Hash Table, Union Find.
Medium - Valid Palindrome
Valid Palindrome (Easy): A phrase is a palindrome if, after converting uppercase to lowercase and removing all non-alphanumeric… Topics: String, Two Pointers.
Easy - Two Sum II - Input Array Is Sorted
Two Sum II - Input Array Is Sorted (Medium): Given a 1-indexed array numbers sorted in non-decreasing order, find… Topics: Array, Two Pointers, Binary Search.
Medium - 3Sum
3Sum (Medium): Given an integer array nums , return all unique triplets [a, b, c] that sum to 0. The result may be in… Topics: Array, Two Pointers, Sorting.
Medium - Container With Most Water
Container With Most Water (Medium): Given an integer array height of length n, find two lines that together with the… Topics: Array, Two Pointers, Greedy.
Medium - Trapping Rain Water
Trapping Rain Water (Hard): Given n non-negative integers representing an elevation map where the width of each bar is 1,… Topics: Array, Two Pointers, Stack.
Hard - Best Time to Buy and Sell Stock
Best Time to Buy and Sell Stock (Easy): You are given an array prices where prices[i] is the price of a stock on day i .… Topics: Array, Dynamic Programming.
Easy - Longest Substring Without Repeating Characters
Longest Substring Without Repeating Characters (Medium): Given a string s , find the length of the longest… Topics: String, Sliding Window, Hash Table.
Medium - Longest Repeating Character Replacement
Longest Repeating Character Replacement (Medium): Given a string s of uppercase English letters and an integer k ,… Topics: String, Sliding Window, Hash Table.
Medium - Permutation in String
Permutation in String (Medium): Given two strings s1 and s2 , return true if s2 contains a permutation of s1 as a… Topics: String, Sliding Window, Hash Table.
Medium - Minimum Window Substring
Minimum Window Substring (Hard): Given two strings s and t , return the smallest substring of s that contains… Topics: Hash Table, String, Sliding Window.
Hard - Sliding Window Maximum
Sliding Window Maximum (Hard): Given an array nums and a window size k , the window slides from left to right one… Topics: Array, Sliding Window, Heap.
Hard - Valid Parentheses
Valid Parentheses (Easy): Given a string s containing just ()[]{} , determine if the input is valid: brackets are closed by the same… Topics: String, Stack.
Easy - Min Stack
Min Stack (Medium): Design a stack that supports push, pop, top, and retrieving the minimum element in constant time. Implement… Topics: Stack, Design.
Medium - Evaluate Reverse Polish Notation
Evaluate Reverse Polish Notation (Medium): Evaluate an arithmetic expression in Reverse Polish Notation given as a list of tokens… Topics: Array, Stack, Math.
Medium - Generate Parentheses
Generate Parentheses (Medium): Given n pairs of parentheses, return all combinations of well-formed… Topics: String, Backtracking, Dynamic Programming.
Medium - Daily Temperatures
Daily Temperatures (Medium): Given an array temperatures , return an array answer where answer[i] is the number of days… Topics: Array, Stack, Monotonic Stack.
Medium - Car Fleet
Car Fleet (Medium): Cars head to a destination at target . Car i starts at position[i] with constant speed[i] ; a faster car… Topics: Array, Stack, Sorting.
Medium - Largest Rectangle in Histogram
Largest Rectangle in Histogram (Hard): Given an array heights of bar heights (each width 1), return the area of the… Topics: Array, Stack, Monotonic Stack.
Hard - Binary Search
Binary Search (Easy): Given a sorted (ascending) array nums of distinct integers and a target , return its index, or -1 if not… Topics: Array, Binary Search.
Easy - Search a 2D Matrix
Search a 2D Matrix (Medium): You are given an m x n matrix where each row is sorted ascending and the first integer of… Topics: Array, Binary Search, Matrix.
Medium - Koko Eating Bananas
Koko Eating Bananas (Medium): Koko has piles of bananas ( nums ) and h hours (passed as target ) before the guards return. Each… Topics: Array, Binary Search.
Medium - Find Minimum in Rotated Sorted Array
Find Minimum in Rotated Sorted Array (Medium): A sorted array of unique integers was rotated at some pivot. Given the array nums… Topics: Array, Binary Search.
Medium - Search in Rotated Sorted Array
Search in Rotated Sorted Array (Medium): Given a rotated ascending array of distinct integers nums and a target , return its… Topics: Array, Binary Search.
Medium - Time Based Key-Value Store
Time Based Key-Value Store (Medium): Design TimeMap with set(key, value, timestamp) and get(key, timestamp) . get… Topics: Hash Table, Binary Search, Design.
Medium - Median of Two Sorted Arrays
Median of Two Sorted Arrays (Hard): Given two sorted arrays nums1 and nums2 of size m and n respectively,… Topics: Array, Binary Search, Divide and Conquer.
Hard - Reverse Linked List
Reverse Linked List (Easy): Given the head of a singly linked list, reverse the list and return the new head. Lists are shown… Topics: Linked List, Recursion.
Easy - Merge Two Sorted Lists
Merge Two Sorted Lists (Easy): You are given the heads of two sorted linked lists l1 and l2 . Splice them into one sorted list… Topics: Linked List, Recursion.
Easy - Reorder List
Reorder List (Medium): Given the head of a singly linked list L0 → L1 → ... → Ln-1 → Ln ,… Topics: Linked List, Two Pointers, Stack.
Medium - Remove Nth Node From End of List
Remove Nth Node From End of List (Medium): Given the head of a linked list, remove the k -th node from the end and return… Topics: Linked List, Two Pointers.
Medium - Add Two Numbers
Add Two Numbers (Medium): You are given two non-empty linked lists representing two non-negative integers. The digits… Topics: Linked List, Math, Recursion.
Medium - Linked List Cycle
Linked List Cycle (Easy): Given the head of a linked list, return true if it has a cycle. On this judge the… Topics: Linked List, Two Pointers, Hash Table.
Easy - Find the Duplicate Number
Find the Duplicate Number (Medium): Given an array nums of n+1 integers where each value is in [1, n] , exactly… Topics: Array, Two Pointers, Binary Search.
Medium - LRU Cache
LRU Cache (Medium): Design an LRU (Least Recently Used) cache with get(key) and put(key, value) , both O(1). The… Topics: Hash Table, Linked List, Design.
Medium - Merge k Sorted Lists
Merge k Sorted Lists (Hard): You are given an array of k sorted linked lists. Merge them into one sorted list… Topics: Linked List, Heap, Divide and Conquer.
Hard - Reverse Nodes in k-Group
Reverse Nodes in k-Group (Hard): Given the head of a linked list, reverse the nodes k at a time and return the modified list.… Topics: Linked List, Recursion.
Hard - Invert Binary Tree
Invert Binary Tree (Easy): Given the root of a binary tree, invert it (swap every left and right child) and return the root. Output is… Topics: Tree, DFS, BFS.
Easy - Maximum Depth of Binary Tree
Maximum Depth of Binary Tree (Easy): Given the root of a binary tree, return its maximum depth — the number of nodes along the longest… Topics: Tree, DFS, BFS.
Easy - Diameter of Binary Tree
Diameter of Binary Tree (Easy): Given the root of a binary tree, return the length of its diameter — the number of edges on the longest… Topics: Tree, DFS.
Easy - Balanced Binary Tree
Balanced Binary Tree (Easy): Given a binary tree, determine if it is height-balanced — for every node, the heights of its two subtrees… Topics: Tree, DFS.
Easy - Same Tree
Same Tree (Easy): Given the roots of two binary trees p and q , return true if they are structurally identical and the nodes have the… Topics: Tree, DFS, BFS.
Easy - Subtree of Another Tree
Subtree of Another Tree (Easy): Given the roots of two binary trees root and subRoot , return true if subRoot appears as a… Topics: Tree, DFS, String Matching.
Easy - Lowest Common Ancestor of a Binary Search Tree
Lowest Common Ancestor of a Binary Search Tree (Medium): Given a binary search tree and two node values p and q present in it, return… Topics: Tree, DFS, BST.
Medium - Binary Tree Level Order Traversal
Binary Tree Level Order Traversal (Medium): Given the root of a binary tree, return its level-order traversal — a list of levels, each a… Topics: Tree, BFS.
Medium - Binary Tree Right Side View
Binary Tree Right Side View (Medium): Given the root of a binary tree, imagine standing on the right side. Return the values of the… Topics: Tree, BFS, DFS.
Medium - Count Good Nodes in Binary Tree
Count Good Nodes in Binary Tree (Medium): A node is good if no node on the path from the root to it has a greater value. Given the… Topics: Tree, DFS, BFS.
Medium - Validate Binary Search Tree
Validate Binary Search Tree (Medium): Given the root of a binary tree, return true if it is a valid binary search tree: every node in… Topics: Tree, DFS, BST.
Medium - Kth Smallest Element in a BST
Kth Smallest Element in a BST (Medium): Given the root of a binary search tree and an integer k , return the k -th smallest value… Topics: Tree, DFS, BST.
Medium - Binary Tree Maximum Path Sum
Binary Tree Maximum Path Sum (Hard): A path is any sequence of nodes connected by parent-child edges; it need not pass… Topics: Tree, DFS, Dynamic Programming.
Hard - Serialize and Deserialize Binary Tree
Serialize and Deserialize Binary Tree (Hard): Serialization turns a tree into a string; deserialization turns that string back into… Topics: String, Tree, DFS.
Hard - Implement Trie (Prefix Tree)
Implement Trie (Prefix Tree) (Medium): Implement a trie with insert(word) , search(word) (returns whether the exact word was… Topics: Trie, Design, Hash Table.
Medium - Design Add and Search Words Data Structure
Design Add and Search Words Data Structure (Medium): Design a data structure with addWord(word) and search(word) . In search, a .… Topics: Trie, Design, DFS.
Medium - Kth Largest Element in an Array
Kth Largest Element in an Array (Medium): Given an integer array nums and an integer k (passed as target ), return the k -th… Topics: Array, Heap, Quickselect.
Medium - Last Stone Weight
Last Stone Weight (Easy): You are given stones weights. Each turn, smash the two heaviest together: if equal both are destroyed,… Topics: Array, Heap, Greedy.
Easy - Task Scheduler
Task Scheduler (Medium): Given a string tasks of uppercase-letter task types and a cooldown n (passed as the second value), each… Topics: Array, Greedy, Heap.
Medium - Find Median from Data Stream
Find Median from Data Stream (Hard): The median is the middle value in an ordered list; for an even-sized list it is the… Topics: Heap, Design, Two Pointers.
Hard - Subsets
Subsets (Medium): Given an array nums of unique integers, return all possible subsets (the power set). The… Topics: Array, Backtracking, Bit Manipulation.
Medium - Combination Sum
Combination Sum (Medium): Given distinct positive integers candidates and a target , return all unique combinations that sum to… Topics: Array, Backtracking.
Medium - Permutations
Permutations (Medium): Given an array nums of distinct integers, return all possible permutations in any order. Topics: Array, Backtracking.
Medium - Subsets II
Subsets II (Medium): Given an integer array nums that may contain duplicates, return all possible unique… Topics: Array, Backtracking, Bit Manipulation.
Medium - Combination Sum II
Combination Sum II (Medium): Given candidates (which may contain duplicates) and a target , return all unique combinations… Topics: Array, Backtracking.
Medium - Word Search
Word Search (Medium): Given an m x n grid of characters board and a string word , return true if the word can be formed… Topics: Array, Backtracking, Matrix.
Medium - Palindrome Partitioning
Palindrome Partitioning (Medium): Given a string s , partition it so that every substring of the partition… Topics: String, Backtracking, Dynamic Programming.
Medium - Letter Combinations of a Phone Number
Letter Combinations of a Phone Number (Medium): Given a string of digits from 2-9, return all letter combinations… Topics: String, Backtracking, Hash Table.
Medium - N-Queens
N-Queens (Hard): The n-queens puzzle places n queens on an n x n chessboard so that no two queens attack each other (no shared row,… Topics: Backtracking.
Hard - Number of Islands
Number of Islands (Medium): Given an m x n grid of '1' (land) and '0' (water), return the number of islands. An island is surrounded… Topics: Graph, DFS, BFS.
Medium - Max Area of Island
Max Area of Island (Medium): Given an m x n binary grid, return the area (number of cells) of the largest island. Cells connect… Topics: Graph, DFS, BFS.
Medium - Walls and Gates
Walls and Gates (Medium): Fill each empty room with the distance to its nearest gate. -1 is a wall, 0 is a gate, and 2147483647… Topics: Graph, BFS, Matrix.
Medium - Rotting Oranges
Rotting Oranges (Medium): In an m x n grid each cell is 0 (empty), 1 (fresh orange), or 2 (rotten). Every minute, a fresh orange… Topics: Graph, BFS, Matrix.
Medium - Pacific Atlantic Water Flow
Pacific Atlantic Water Flow (Medium): You are given an m x n grid heights representing the height of each cell on an island. The… Topics: Array, DFS, BFS.
Medium - Surrounded Regions
Surrounded Regions (Medium): Given an m x n board of 'X' and 'O' , capture all regions of 'O' that are fully surrounded by 'X' (flip… Topics: Graph, DFS, BFS.
Medium - Course Schedule
Course Schedule (Medium): There are n courses labeled 0..n-1. edges[i] = [a, b] means you must take course b before… Topics: Graph, Topological Sort, DFS.
Medium - Course Schedule II
Course Schedule II (Medium): There are n courses labelled 0 to n - 1 . You are given edges where edges[i] = [a, b] means… Topics: Graph, Topological Sort, BFS.
Medium - Graph Valid Tree
Graph Valid Tree (Medium): Given n nodes labeled 0..n-1 and a list of undirected edges , return true if the graph is a valid… Topics: Graph, Union Find, DFS.
Medium - Number of Connected Components in an Undirected Graph
Number of Connected Components in an Undirected Graph (Medium): Given n nodes labeled 0..n-1 and a list of undirected edges ,… Topics: Graph, Union Find, DFS.
Medium - Redundant Connection
Redundant Connection (Medium): A tree on nodes 1..n had one extra edge added, creating exactly one cycle. Given the edges in input… Topics: Graph, Union Find.
Medium - Word Ladder
Word Ladder (Hard): Given beginWord , endWord , and a wordList , return the number of words in the shortest transformation… Topics: Graph, BFS, Hash Table.
Hard - Reconstruct Itinerary
Reconstruct Itinerary (Hard): You are given a list of one-way flight tickets. Reconstruct the itinerary that starts at… Topics: Graph, DFS, Eulerian Circuit.
Hard - Min Cost to Connect All Points
Min Cost to Connect All Points (Medium): You are given points where points[i] = [x, y] . The cost to connect two… Topics: Graph, Minimum Spanning Tree, Heap.
Medium - Network Delay Time
Network Delay Time (Medium): You are given directed weighted edges times where times[i] = [u, v, w] , n nodes labeled 1..n, and… Topics: Graph, Dijkstra, Heap.
Medium - Swim in Rising Water
Swim in Rising Water (Hard): You are given an n x n grid where grid[i][j] is the elevation at that cell. At time t the… Topics: Graph, Binary Search, Heap.
Hard - Alien Dictionary
Alien Dictionary (Hard): There is a new alien language that uses the English alphabet. However, the order among letters… Topics: Graph, Topological Sort, BFS.
Hard - Cheapest Flights Within K Stops
Cheapest Flights Within K Stops (Medium): There are n cities labelled 0 to n - 1 and a list of flights, where each… Topics: Dynamic Programming, Graph, Heap.
Medium - Climbing Stairs
Climbing Stairs (Easy): You are climbing a staircase with n steps. Each time you can climb 1 or 2 steps. In how many… Topics: Dynamic Programming, Math.
Easy - Min Cost Climbing Stairs
Min Cost Climbing Stairs (Easy): Given an array cost where cost[i] is the cost of step i , you can climb 1 or 2 steps and… Topics: Array, Dynamic Programming.
Easy - House Robber
House Robber (Medium): You are a robber planning to rob houses along a street. You cannot rob two adjacent houses. Given… Topics: Array, Dynamic Programming.
Medium - House Robber II
House Robber II (Medium): Same as House Robber, but the houses are arranged in a circle — the first and last are adjacent.… Topics: Array, Dynamic Programming.
Medium - Longest Palindromic Substring
Longest Palindromic Substring (Medium): A palindrome reads identically from left to right and from right to… Topics: String, Two Pointers, Dynamic Programming.
Medium - Palindromic Substrings
Palindromic Substrings (Medium): Given a string s , return the number of palindromic substrings in it.… Topics: String, Dynamic Programming, Two Pointers.
Medium - Decode Ways
Decode Ways (Medium): A message of digits is encoded to letters using the mapping 'A' -> 1 , ..., 'Z' -> 26 . Given a… Topics: String, Dynamic Programming.
Medium - Coin Change
Coin Change (Medium): Given an array coins (passed as nums ) and an integer amount (passed as target ), return the fewest… Topics: Array, Dynamic Programming.
Medium - Maximum Product Subarray
Maximum Product Subarray (Medium): Given an integer array nums , find a contiguous non-empty subarray that has the largest… Topics: Array, Dynamic Programming.
Medium - Word Break
Word Break (Medium): Given a string s and a dictionary of strings wordDict , return true if s can be… Topics: String, Dynamic Programming, Hash Table.
Medium - Unique Paths
Unique Paths (Medium): A robot sits at the top-left of an m x n grid and can only move right or down .… Topics: Math, Dynamic Programming, Combinatorics.
Medium - Longest Common Subsequence
Longest Common Subsequence (Medium): Given two strings text1 and text2 , return the length of their longest common… Topics: String, Dynamic Programming.
Medium - Best Time to Buy and Sell Stock with Cooldown
Best Time to Buy and Sell Stock with Cooldown (Medium): Given daily stock prices , maximize profit with as many… Topics: Array, Dynamic Programming.
Medium - Coin Change II
Coin Change II (Medium): You are given coin denominations nums and a target amount k . Return the number of distinct… Topics: Array, Dynamic Programming.
Medium - Target Sum
Target Sum (Medium): Given an array nums and an integer target k , assign a + or - to each number and count… Topics: Array, Dynamic Programming, Backtracking.
Medium - Interleaving String
Interleaving String (Medium): Given strings s1 , s2 , and s3 , return true if s3 is formed by an interleaving of s1 and… Topics: String, Dynamic Programming.
Medium - Longest Increasing Path in a Matrix
Longest Increasing Path in a Matrix (Hard): Given an m x n integer matrix, return the length of the longest strictly… Topics: Graph, DFS, Dynamic Programming.
Hard - Distinct Subsequences
Distinct Subsequences (Hard): Given two strings s and t , return the number of distinct subsequences of s that equal t .… Topics: String, Dynamic Programming.
Hard - Edit Distance
Edit Distance (Medium): Given two strings word1 and word2 , return the minimum number of operations (insert, delete, or… Topics: String, Dynamic Programming.
Medium - Burst Balloons
Burst Balloons (Hard): You have n balloons with numbers in nums . Bursting balloon i gives… Topics: Array, Dynamic Programming, Interval DP.
Hard - Regular Expression Matching
Regular Expression Matching (Hard): Given a string s (first line) and a pattern p (second line) supporting .… Topics: String, Dynamic Programming, Recursion.
Hard - Maximum Subarray
Maximum Subarray (Medium): Given an integer array nums , find the contiguous subarray with the largest sum and return its… Topics: Array, Dynamic Programming.
Medium - Jump Game
Jump Game (Medium): Given an array nums where each element is your maximum jump length from that position, return… Topics: Array, Greedy, Dynamic Programming.
Medium - Jump Game II
Jump Game II (Medium): Given an array nums where nums[i] is the maximum jump length from index i , return the… Topics: Array, Greedy, Dynamic Programming.
Medium - Gas Station
Gas Station (Medium): A delivery van drives a one-way ring road with n fuel stops numbered 0 to n - 1 . At stop i it can take on gas[i]… Topics: Array, Greedy.
Medium - Hand of Straights
Hand of Straights (Medium): Given an array hand of card values and a group size k (LeetCode: groupSize), return true if the… Topics: Array, Greedy, Hash Table.
Medium - Merge Triplets to Form Target Triplet
Merge Triplets to Form Target Triplet (Medium): You are given triplets and a target triplet. A merge replaces the running triplet with… Topics: Array, Greedy.
Medium - Partition Labels
Partition Labels (Medium): You are given a string s . Partition it into as many parts as possible so that each letter… Topics: String, Greedy, Two Pointers.
Medium - Valid Parenthesis String
Valid Parenthesis String (Medium): Given a string s containing only ( , ) and * , return true if it can be made a… Topics: String, Greedy, Dynamic Programming.
Medium - Merge Intervals
Merge Intervals (Medium): Given an array of intervals (each [start, end] ), merge all overlapping intervals and return the… Topics: Array, Sorting, Intervals.
Medium - Non-overlapping Intervals
Non-overlapping Intervals (Medium): Given an array of intervals (each [start, end] ), return the minimum number of intervals… Topics: Array, Greedy, Sorting.
Medium - Meeting Rooms
Meeting Rooms (Easy): Given an array of meeting time intervals where intervals[i] = [start, end] , return true if a person… Topics: Array, Sorting, Intervals.
Easy - Meeting Rooms II
Meeting Rooms II (Medium): Given meeting intervals (each [start, end] ), return the minimum number of conference rooms required. Topics: Array, Heap, Sorting.
Medium - Rotate Image
Rotate Image (Medium): Given an n x n matrix, rotate it 90 degrees clockwise. LeetCode mutates in place and returns void; here… Topics: Array, Math, Matrix.
Medium - Spiral Matrix
Spiral Matrix (Medium): Given an m x n matrix, return all elements in spiral order (clockwise starting from the top-left). Topics: Array, Matrix, Simulation.
Medium - Set Matrix Zeroes
Set Matrix Zeroes (Medium): Given an m x n matrix, if an element is 0 set its entire row and column to 0. LeetCode mutates… Topics: Array, Hash Table, Matrix.
Medium - Happy Number
Happy Number (Easy): A number is happy if repeatedly replacing it by the sum of the squares of its digits eventually… Topics: Math, Hash Table, Two Pointers.
Easy - Plus One
Plus One (Easy): You are given a large integer as an array of digits digits (most significant first). Increment it by one and return the… Topics: Array, Math.
Easy - Multiply Strings
Multiply Strings (Medium): Given two non-negative integers num1 and num2 represented as strings, return the product, also as… Topics: String, Math, Simulation.
Medium - Single Number
Single Number (Easy): Given a non-empty array nums where every element appears twice except one, find that single one. Do it… Topics: Array, Bit Manipulation.
Easy - Number of 1 Bits
Number of 1 Bits (Easy): Given a non-negative integer n , return the number of set bits (1s) in its binary representation (its… Topics: Bit Manipulation.
Easy - Counting Bits
Counting Bits (Easy): Given an integer n , return an array ans of length n + 1 where ans[i] is the number of 1… Topics: Dynamic Programming, Bit Manipulation.
Easy - Reverse Bits
Reverse Bits (Easy): Reverse the bits of a given 32-bit unsigned integer. Return the resulting unsigned integer represented as a… Topics: Bit Manipulation.
Easy - Missing Number
Missing Number (Easy): Given an array nums containing n distinct numbers in the range [0, n] , return the only number… Topics: Array, Math, Bit Manipulation.
Easy - Sum of Two Integers
Sum of Two Integers (Medium): Given two integers a and b , return their sum without using the operators + or - . Topics: Math, Bit Manipulation.
Medium - Reverse Integer
Reverse Integer (Medium): Given a signed 32-bit integer x , return x with its digits reversed. If reversing causes the value to fall outside the… Topics: Math.
Medium - Maximum Product of Word Lengths
Maximum Product of Word Lengths (Medium): Given an array of strings words , return the maximum value of… Topics: Array, String, Bit Manipulation.
Medium - Longest Increasing Subsequence
Longest Increasing Subsequence (Medium): Given an integer array nums , return the length of the longest… Topics: Array, Binary Search, Dynamic Programming.
Medium - Add Binary
Add Binary (Easy): Given two binary strings s and t , return their sum as a binary string. The inputs carry no leading… Topics: Math, String, Bit Manipulation.
Easy - Add Digits
Add Digits (Easy): Given a non-negative integer n , repeatedly add all its digits until the result has only one digit, and return it. Topics: Math, Simulation.
Easy - Add Strings
Add Strings (Easy): Given two non-negative integers num1 and num2 represented as strings, return their sum as a string. You… Topics: Math, String, Simulation.
Easy - Arranging Coins
Arranging Coins (Easy): You have n coins and want to build a staircase where row i holds exactly i coins. The last row may be… Topics: Math, Binary Search.
Easy - Array Partition
Array Partition (Easy): Given an array nums of 2n integers, group them into n pairs so that the sum of min(pair) over all… Topics: Array, Greedy, Sorting.
Easy - Backspace String Compare
Backspace String Compare (Easy): Given two strings s and t , return true if they are equal after typing them into empty… Topics: String, Stack, Two Pointers.
Easy - Baseball Game
Baseball Game (Easy): You are given operations as a space-separated string s . Each token is an integer (record it), "+" (sum of… Topics: Stack, Simulation.
Easy - Binary Tree Inorder Traversal
Binary Tree Inorder Traversal (Easy): Given the root of a binary tree, return its inorder traversal (left, node, right) as a list of… Topics: Tree, DFS, Stack.
Easy - Binary Tree Postorder Traversal
Binary Tree Postorder Traversal (Easy): Given the root of a binary tree, return its postorder traversal (left, right, node) as a… Topics: Tree, DFS, Stack.
Easy - Binary Tree Preorder Traversal
Binary Tree Preorder Traversal (Easy): Given the root of a binary tree, return its preorder traversal (node, left, right) as a list… Topics: Tree, DFS, Stack.
Easy - Binary Tree Tilt
Binary Tree Tilt (Easy): The tilt of a node is the absolute difference between the sum of all values in its left subtree and the sum of all… Topics: Tree, DFS.
Easy - Build Array from Permutation
Build Array from Permutation (Easy): Given a zero-based permutation nums , build an array ans of the same length where ans[i] =… Topics: Array, Simulation.
Easy - Can Place Flowers
Can Place Flowers (Easy): hand is a flowerbed where 0 is an empty plot and 1 holds a flower. Flowers cannot be planted in adjacent… Topics: Array, Greedy.
Easy - Concatenation of Array
Concatenation of Array (Easy): Given an array nums of length n, return an array ans of length 2n where ans[i] = nums[i] and… Topics: Array, Simulation.
Easy - Contains Duplicate II
Contains Duplicate II (Easy): Given an integer array nums and an integer k , return true if there are two distinct… Topics: Array, Hash Table, Sliding Window.
Easy - Count Binary Substrings
Count Binary Substrings (Easy): Given a binary string s , count the non-empty substrings that have equal numbers of 0s and 1s ,… Topics: Two Pointers, String.
Easy - Count Complete Tree Nodes
Count Complete Tree Nodes (Easy): Given the root of a binary tree, return the total number of nodes. Topics: Tree, DFS, Binary Search.
Easy - Count Vowel Substrings of a String
Count Vowel Substrings of a String (Easy): A vowel substring is a contiguous, non-empty piece of s that consists… Topics: Hash Table, String, Sliding Window.
Easy - Design HashMap
Design HashMap (Easy): Design a HashMap without using any built-in hash table libraries. Implement MyHashMap with put(key,… Topics: Array, Hash Table, Design.
Easy - Design HashSet
Design HashSet (Easy): Design a HashSet without using any built-in hash set libraries. Implement MyHashSet with add(key) ,… Topics: Array, Hash Table, Design.
Easy - Design Parking System
Design Parking System (Easy): Design a parking system for a lot with three kinds of spaces: big, medium, and small, with… Topics: Design, Counting, Simulation.
Easy - Detect Capital
Detect Capital (Easy): Given a word s , return true if its capital usage is correct: all uppercase, all lowercase, or only the first letter… Topics: String.
Easy - Excel Sheet Column Number
Excel Sheet Column Number (Easy): Given a spreadsheet column title s (as in Excel: A, B, ..., Z, AA, AB, ...), return its corresponding… Topics: Math, String.
Easy - Fibonacci Number
Fibonacci Number (Easy): The Fibonacci numbers satisfy F(0)=0 , F(1)=1 , and F(n)=F(n-1)+F(n-2) for n > 1. Given… Topics: Math, Dynamic Programming, Recursion.
Easy - Find All Numbers Disappeared in an Array
Find All Numbers Disappeared in an Array (Easy): Given an array nums of n integers where nums[i] is in the range [1, n] , return an… Topics: Array, Hash Table.
Easy - Find Center of Star Graph
Find Center of Star Graph (Easy): You are given an undirected star graph of n nodes labeled 1..n. A star graph has one center node connected to… Topics: Graph.
Easy - Find if Path Exists in Graph
Find if Path Exists in Graph (Easy): There is a bi-directional graph with n vertices labeled 0..n-1, described by the list of… Topics: Graph, DFS, BFS.
Easy - Find Numbers with Even Number of Digits
Find Numbers with Even Number of Digits (Easy): Given an array nums of integers, return how many of them contain an even number of digits. Topics: Array, Math.
Easy - Find Pivot Index
Find Pivot Index (Easy): Given an array nums , return the leftmost pivot index : the index where the sum of all numbers strictly to… Topics: Array, Prefix Sum.
Easy - Find Target Indices After Sorting the Array
Find Target Indices After Sorting the Array (Easy): Given an array nums and an integer target , first sort nums in… Topics: Array, Binary Search, Sorting.
Easy - Find the Highest Altitude
Find the Highest Altitude (Easy): A biker starts at altitude 0. gain[i] is the net gain between point i and i+1. Return the highest… Topics: Array, Prefix Sum.
Easy - Find the Index of the First Occurrence in a String
Find the Index of the First Occurrence in a String (Easy): Given two strings s (haystack) and t (needle), return the index of… Topics: String, Two Pointers.
Easy - Find the Town Judge
Find the Town Judge (Easy): In a town of n people labeled 1..n, exactly one person may be the town judge. Each edge [a, b]… Topics: Graph, Array, Hash Table.
Easy - First Unique Character in a String
First Unique Character in a String (Easy): Given a string s , return the index of the first non-repeating character. If… Topics: String, Hash Table, Queue.
Easy - Fizz Buzz
Fizz Buzz (Easy): Given an integer n , return a string array answer of length n where, for each i from 1 to n : answer[i-1]… Topics: Math, String, Simulation.
Easy - Hamming Distance
Hamming Distance (Easy): The Hamming distance between two integers is the number of positions at which the corresponding bits… Topics: Bit Manipulation.
Easy - How Many Numbers Are Smaller Than the Current Number
How Many Numbers Are Smaller Than the Current Number (Easy): For each nums[i] , count how many nums[j] (j != i) are… Topics: Array, Hash Table, Counting.
Easy - Implement Queue using Stacks
Implement Queue using Stacks (Easy): Implement a first-in-first-out (FIFO) queue using only two stacks. Implement MyQueue with… Topics: Stack, Queue, Design.
Easy - Implement Stack using Queues
Implement Stack using Queues (Easy): Implement a last-in-first-out (LIFO) stack using only queues. Implement MyStack with… Topics: Stack, Queue, Design.
Easy - Intersection of Two Arrays
Intersection of Two Arrays (Easy): Given two integer arrays a and b , return the values that appear in both . Each… Topics: Array, Hash Table, Two Pointers.
Easy - Is Subsequence
Is Subsequence (Easy): Given two strings s and t , return true if s is a subsequence of t (formed by… Topics: String, Two Pointers, Dynamic Programming.
Easy - Island Perimeter
Island Perimeter (Easy): Given a binary grid where 1 is land and 0 is water, return the total perimeter of the land. Each land cell… Topics: Array, DFS, BFS.
Easy - Isomorphic Strings
Isomorphic Strings (Easy): Given two strings s and t , return true if they are isomorphic — the characters in s can be replaced to… Topics: Hash Table, String.
Easy - Kth Largest Element in a Stream
Kth Largest Element in a Stream (Easy): Design a class to find the k th largest element in a stream (the kth largest… Topics: Heap, Design, Binary Search Tree.
Easy - Kth Missing Positive Number
Kth Missing Positive Number (Easy): Given a strictly increasing array of positive integers nums and an integer target (= k),… Topics: Array, Binary Search.
Easy - Length of Last Word
Length of Last Word (Easy): Given a string s of words and spaces, return the length of the last word. A word is a maximal substring of… Topics: String.
Easy - Logger Rate Limiter
Logger Rate Limiter (Easy): Design a logger that limits each unique message to being printed at most once every 10… Topics: Hash Table, Design, Data Stream.
Easy - Longest Common Prefix
Longest Common Prefix (Easy): You are given a list of non-empty words. Return the longest string that every word in the list starts… Topics: String, Trie.
Easy - Longest Palindrome
Longest Palindrome (Easy): Given a string s of lowercase and/or uppercase letters, return the length of the longest… Topics: Hash Table, String, Greedy.
Easy - Majority Element
Majority Element (Easy): Given an array nums of size n, return the majority element (the one appearing more than n/2 times). It… Topics: Array, Hash Table.
Easy - Make The String Great
Make The String Great (Easy): A good string has no two adjacent characters where one is the lowercase and the other the uppercase of… Topics: String, Stack.
Easy - Max Consecutive Ones
Max Consecutive Ones (Easy): Given a binary array nums , return the maximum number of consecutive 1 s. Topics: Array.
Easy - Maximum Ascending Subarray Sum
Maximum Ascending Subarray Sum (Easy): Given an array nums , return the maximum possible sum of a strictly ascending contiguous subarray. Topics: Array.
Easy - Maximum Count of Positive Integer and Negative Integer
Maximum Count of Positive Integer and Negative Integer (Easy): Given a sorted array nums in non-decreasing order,… Topics: Array, Binary Search, Counting.
Easy - Maximum Product of Three Numbers
Maximum Product of Three Numbers (Easy): Given an integer array nums , find three numbers whose product is maximum and return… Topics: Array, Math, Sorting.
Easy - Maximum Product of Two Elements in an Array
Maximum Product of Two Elements in an Array (Easy): Given an array nums , choose two different indices i and j and return the maximum… Topics: Array, Sorting.
Easy - Merge Sorted Array
Merge Sorted Array (Easy): You are given two integer arrays a and b , each sorted in non-decreasing order. Return a… Topics: Array, Two Pointers, Sorting.
Easy - Merge Strings Alternately
Merge Strings Alternately (Easy): Merge s and t by taking characters alternately, starting with s . If one string is longer,… Topics: Two Pointers, String.
Easy - Middle of the Linked List
Middle of the Linked List (Easy): Given the head of a singly linked list, return the list starting from the middle node. If… Topics: Linked List, Two Pointers.
Easy - Minimum Absolute Difference
Minimum Absolute Difference (Easy): Given an array of distinct integers arr , find all pairs of elements with the minimum absolute… Topics: Array, Sorting.
Easy - Minimum Absolute Difference in BST
Minimum Absolute Difference in BST (Easy): Given the root of a Binary Search Tree, return the minimum absolute difference between the… Topics: Tree, DFS, BST.
Easy - Minimum Cost to Move Chips to The Same Position
Minimum Cost to Move Chips to The Same Position (Easy): Chips are at positions given by nums . Moving a chip by 2 costs 0; moving… Topics: Array, Math, Greedy.
Easy - Minimum Depth of Binary Tree
Minimum Depth of Binary Tree (Easy): Given the root of a binary tree, return its minimum depth — the number of nodes along the… Topics: Tree, DFS, BFS.
Easy - Minimum Value to Get Positive Step by Step Sum
Minimum Value to Get Positive Step by Step Sum (Easy): Given an array nums , pick a positive start value. The step-by-step total… Topics: Array, Prefix Sum.
Easy - Monotonic Array
Monotonic Array (Easy): An array is monotonic if it is entirely non-increasing or entirely non-decreasing. Given nums , return true if it is… Topics: Array.
Easy - Move Zeroes
Move Zeroes (Easy): Given an integer array nums , move all 0 's to the end while keeping the relative order of the non-zero… Topics: Array, Two Pointers.
Easy - Moving Average from Data Stream
Moving Average from Data Stream (Easy): Given a stream of integers and a window size, calculate the moving average of all… Topics: Array, Queue, Design.
Easy - Next Greater Element I
Next Greater Element I (Easy): a is a subset of b , and all values in both arrays are distinct . For each value in a , find… Topics: Array, Hash Table, Stack.
Easy - Nim Game
Nim Game (Easy): You are playing Nim: a heap of n stones, players alternate removing 1 to 3 stones, and whoever removes the last… Topics: Math, Game Theory.
Easy - Number Complement
Number Complement (Easy): The complement of an integer is the number you get by flipping all the bits in its binary representation… Topics: Bit Manipulation.
Easy - Number of Good Pairs
Number of Good Pairs (Easy): Given an array nums , a pair (i, j) is good if nums[i] == nums[j] and i j . Return the number… Topics: Array, Hash Table, Math.
Easy - Number of Recent Calls
Number of Recent Calls (Easy): Implement RecentCounter that counts recent requests within a time window. Implement ping(t)… Topics: Queue, Design, Data Stream.
Easy - Number of Steps to Reduce a Number to Zero
Number of Steps to Reduce a Number to Zero (Easy): Given an integer n , return the number of steps to reduce it to zero. In… Topics: Math, Bit Manipulation.
Easy - Palindrome Linked List
Palindrome Linked List (Easy): Given the head of a singly linked list, return true if the sequence of values reads… Topics: Linked List, Two Pointers, Stack.
Easy - Palindrome Number
Palindrome Number (Easy): Given an integer n , return true if it is a palindrome (reads the same backward as forward). Negative numbers are not… Topics: Math.
Easy - Pascal's Triangle
Pascal's Triangle (Easy): Given an integer n , return the first n rows of Pascal’s triangle . Each row starts and ends… Topics: Array, Dynamic Programming.
Easy - Perfect Number
Perfect Number (Easy): A perfect number equals the sum of its positive divisors excluding itself. Given an integer n , return true if it is a… Topics: Math.
Easy - Power of Four
Power of Four (Easy): Given an integer n , return true if it is a power of four (i.e., n == 4^x for some non-negative integer… Topics: Math, Bit Manipulation.
Easy - Power of Three
Power of Three (Easy): Given an integer n , return true if it is a power of three (i.e., n == 3^x for some non-negative integer x). Topics: Math, Recursion.
Easy - Power of Two
Power of Two (Easy): Given an integer n , return true if it is a power of two (i.e., n == 2^x for some non-negative integer x). Topics: Math, Bit Manipulation.
Easy - Range Sum Query - Immutable
Range Sum Query - Immutable (Easy): Given an integer array nums , handle multiple queries of the sum of the elements… Topics: Array, Prefix Sum, Design.
Easy - Ransom Note
Ransom Note (Easy): Given two strings s (the ransom note) and t (the magazine), return true if s can be constructed… Topics: Hash Table, String, Counting.
Easy - Remove All Adjacent Duplicates In String
Remove All Adjacent Duplicates In String (Easy): Given a string s , repeatedly remove two adjacent equal letters until no more can be… Topics: String, Stack.
Easy - Remove Duplicates from Sorted Array
Remove Duplicates from Sorted Array (Easy): Given a sorted integer array nums , remove the duplicates in-place so each unique… Topics: Array, Two Pointers.
Easy - Remove Duplicates from Sorted List
Remove Duplicates from Sorted List (Easy): Given the head of a sorted linked list, delete all duplicates so that each value appears only… Topics: Linked List.
Easy - Remove Element
Remove Element (Easy): Given an array nums and a value target , remove all occurrences of target in-place and return the number… Topics: Array, Two Pointers.
Easy - Remove Linked List Elements
Remove Linked List Elements (Easy): Given the head of a linked list and an integer k , remove all nodes whose value equals k… Topics: Linked List, Recursion.
Easy - Repeated Substring Pattern
Repeated Substring Pattern (Easy): Given a string s , return true if it can be built by repeating a substring of it multiple… Topics: String, String Matching.
Easy - Reverse String
Reverse String (Easy): Given a string s , return the string reversed. Topics: String, Two Pointers.
Easy - Reverse Vowels of a String
Reverse Vowels of a String (Easy): Given a string s , reverse only the vowels ( a e i o u , both cases) and return the result. Topics: String, Two Pointers.
Easy - Reverse Words in a String III
Reverse Words in a String III (Easy): Given a string s of words separated by single spaces, reverse the characters of each word… Topics: String, Two Pointers.
Easy - Rising Temperature
Rising Temperature (Easy): Each row of matrix is a weather reading [id, day, temperature] . The day values are integer day… Topics: Array, Hash Table, Sorting.
Easy - Roman to Integer
Roman to Integer (Easy): Given a Roman numeral string s , convert it to an integer. Symbols: I=1, V=5, X=10, L=50, C=100,… Topics: Hash Table, Math, String.
Easy - Rotate String
Rotate String (Easy): A shift on s moves its leftmost character to the right-hand end, so "abcde" becomes "bcdea" . Return… Topics: String, String Matching.
Easy - Running Sum of 1d Array
Running Sum of 1d Array (Easy): Given an array nums , return its running sum where runningSum[i] = sum(nums[0..i]) . Topics: Array, Prefix Sum.
Easy - Search Insert Position
Search Insert Position (Easy): Given a sorted array of distinct integers nums and a target , return the index if found. If not,… Topics: Array, Binary Search.
Easy - Sqrt(x)
Sqrt(x) (Easy): Given a non-negative integer n , return the integer square root of n (the floor of the true square root). Do not… Topics: Math, Binary Search.
Easy - Squares of a Sorted Array
Squares of a Sorted Array (Easy): Given an array nums sorted in non-decreasing order, return an array of the squares of… Topics: Array, Two Pointers, Sorting.
Easy - Subtract the Product and Sum of Digits of an Integer
Subtract the Product and Sum of Digits of an Integer (Easy): Given an integer n , return the product of its digits minus the sum of its digits. Topics: Math.
Easy - Sum of All Odd Length Subarrays
Sum of All Odd Length Subarrays (Easy): Given an array of positive integers arr , return the sum of all elements over all… Topics: Array, Prefix Sum, Math.
Easy - Sum of Left Leaves
Sum of Left Leaves (Easy): Given the root of a binary tree, return the sum of all left leaves — leaf nodes that are the left child of their… Topics: Tree, DFS.
Easy - Sum of Root To Leaf Binary Numbers
Sum of Root To Leaf Binary Numbers (Easy): Every node has value 0 or 1 . Each root-to-leaf path represents a binary… Topics: Tree, DFS, Bit Manipulation.
Easy - Symmetric Tree
Symmetric Tree (Easy): Given the root of a binary tree, check whether it is a mirror of itself (symmetric around its center). Topics: Tree, DFS, BFS.
Easy - Third Maximum Number
Third Maximum Number (Easy): Given an integer array nums , return the third distinct maximum value. If it does not exist, return the… Topics: Array, Sorting.
Easy - Ugly Number
Ugly Number (Easy): An ugly number is a positive integer whose prime factors are limited to 2 , 3 , and 5 . Given an integer n , return true if… Topics: Math.
Easy - Univalued Binary Tree
Univalued Binary Tree (Easy): A binary tree is univalued if every node has the same value. Given the root , return true if the tree is… Topics: Tree, DFS, BFS.
Easy - Valid Palindrome II
Valid Palindrome II (Easy): Given a string s , return true if it can be a palindrome after deleting at most one character. Topics: String, Two Pointers, Greedy.
Easy - Valid Perfect Square
Valid Perfect Square (Easy): Given a positive integer n , return true if it is a perfect square (the square of some integer), and… Topics: Math, Binary Search.
Easy - Valid Word Abbreviation
Valid Word Abbreviation (Easy): A string can be abbreviated by replacing any number of non-adjacent, non-empty substrings with… Topics: Two Pointers, String.
Easy - 3Sum Closest
3Sum Closest (Medium): Given an array nums and a value target , find three integers whose sum is closest to target and… Topics: Array, Two Pointers, Sorting.
Medium - 4Sum
4Sum (Medium): Given an array nums of n integers and a target , return all unique quadruplets [nums[a], nums[b],… Topics: Array, Two Pointers, Sorting.
Medium - Arithmetic Slices
Arithmetic Slices (Medium): An arithmetic slice is a contiguous subarray of length at least 3 with a constant difference… Topics: Array, Dynamic Programming.
Medium - As Far from Land as Possible
As Far from Land as Possible (Medium): Given a grid where 1 is land and 0 is water, find the water cell whose Manhattan distance… Topics: Graph, BFS, Matrix.
Medium - Asteroid Collision
Asteroid Collision (Medium): Given nums of asteroids (absolute value = size, sign = direction: positive right, negative… Topics: Array, Stack, Simulation.
Medium - Basic Calculator II
Basic Calculator II (Medium): You are given a line s holding an arithmetic expression built from non-negative whole numbers, the… Topics: String, Stack, Math.
Medium - Battleships in a Board
Battleships in a Board (Medium): Given an m x n board where each cell is either 'X' (part of a battleship) or '.' (empty), return… Topics: Array, DFS, Matrix.
Medium - Best Time to Buy and Sell Stock II
Best Time to Buy and Sell Stock II (Medium): You are given an array prices where prices[i] is the price of a stock… Topics: Array, Greedy, Dynamic Programming.
Medium - Binary Tree Vertical Order Traversal
Binary Tree Vertical Order Traversal (Medium): Given the root of a binary tree, return the vertical order traversal of… Topics: Hash Table, Tree, Binary Tree.
Medium - Binary Tree Zigzag Level Order Traversal
Binary Tree Zigzag Level Order Traversal (Medium): Given the root of a binary tree, list its values level by level, alternating direction:… Topics: Tree, BFS.
Medium - Bitwise AND of Numbers Range
Bitwise AND of Numbers Range (Medium): Given two integers a and b with a = b , return the bitwise AND of all numbers in the… Topics: Bit Manipulation.
Medium - Boats to Save People
Boats to Save People (Medium): You are given weights nums and a boat capacity target . Each boat carries at most two… Topics: Array, Greedy, Two Pointers.
Medium - Boundary of Binary Tree
Boundary of Binary Tree (Medium): The boundary of a binary tree is the concatenation of the root, the left boundary , the… Topics: Tree, DFS, Binary Tree.
Medium - Brightest Position on Street
Brightest Position on Street (Medium): A street is the number line. You are given lights , where lights[i] =… Topics: Array, Ordered Set, Prefix Sum.
Medium - Bulb Switcher
Bulb Switcher (Medium): There are n bulbs initially off. On round i you toggle every i -th bulb (round 1 toggles all). After n… Topics: Math, Brainteaser.
Medium - Candy Crush
Candy Crush (Medium): The board is a grid where each cell holds a positive candy type or 0 for empty. Repeat until… Topics: Array, Two Pointers, Matrix.
Medium - Capacity To Ship Packages Within D Days
Capacity To Ship Packages Within D Days (Medium): Package weights nums must be shipped in order within target days. Each day… Topics: Array, Binary Search.
Medium - Car Pooling
Car Pooling (Medium): There is a car with capacity empty seats, driving east and never turning around. You are given trips ,… Topics: Array, Sorting, Heap.
Medium - Consecutive Numbers
Consecutive Numbers (Medium): Each row of matrix is a log entry [id, num] . The ids are distinct but the rows arrive in no particular… Topics: Array, Sorting.
Medium - Contiguous Array
Contiguous Array (Medium): Given a binary array nums , return the maximum length of a contiguous subarray with an equal… Topics: Array, Hash Table, Prefix Sum.
Medium - Count and Say
Count and Say (Medium): The count-and-say sequence starts at "1" . Each later term is produced by reading the previous one aloud: split it… Topics: String.
Medium - Count Nodes Equal to Average of Subtree
Count Nodes Equal to Average of Subtree (Medium): For each node, consider the subtree rooted at it. Count the nodes whose value equals the… Topics: Tree, DFS.
Medium - Count Primes
Count Primes (Medium): Given an integer n , return the number of prime numbers strictly less than n . Topics: Math, Sieve of Eratosthenes.
Medium - Count Servers that Communicate
Count Servers that Communicate (Medium): You are given a grid of 0 s and 1 s where 1 marks a server. Two servers communicate if… Topics: Array, Graph, Matrix.
Medium - Count the Number of Complete Components
Count the Number of Complete Components (Medium): Given n nodes labeled 0..n-1 and a list of undirected edges , return the number of… Topics: Graph, DFS, BFS.
Medium - Decode String
Decode String (Medium): Given an encoded string s following the rule k[encoded] meaning the bracketed part repeats k times, return the… Topics: String, Stack.
Medium - Deepest Leaves Sum
Deepest Leaves Sum (Medium): Given the root of a binary tree, return the sum of values of its deepest leaves. Topics: Tree, BFS, DFS.
Medium - Delete and Earn
Delete and Earn (Medium): You are given an integer array nums . In one operation you pick any element, earn… Topics: Array, Hash Table, Dynamic Programming.
Medium - Delete the Middle Node of a Linked List
Delete the Middle Node of a Linked List (Medium): Given the head of a linked list, delete the middle node (the node at… Topics: Linked List, Two Pointers.
Medium - Design a Leaderboard
Design a Leaderboard (Medium): Design a leaderboard that tracks player scores. Leaderboard() starts empty.… Topics: Hash Table, Design, Sorting.
Medium - Design a Stack With Increment Operation
Design a Stack With Increment Operation (Medium): Design a stack with a bulk-increment operation. Implement CustomStack(maxSize)… Topics: Stack, Array, Design.
Medium - Design Browser History
Design Browser History (Medium): You have a browser with one tab starting on a homepage. Implement BrowserHistory(homepage)… Topics: Array, Linked List, Stack.
Medium - Design Circular Deque
Design Circular Deque (Medium): Design a circular double-ended queue. Implement MyCircularDeque(k) and: insertFront(value) ,… Topics: Array, Queue, Design.
Medium - Design Circular Queue
Design Circular Queue (Medium): Design a circular queue using a fixed-size array. Implement MyCircularQueue(k) and:… Topics: Array, Queue, Design.
Medium - Design Hit Counter
Design Hit Counter (Medium): Design a hit counter that counts hits received in the past 5 minutes (300 seconds).… Topics: Queue, Design, Binary Search.
Medium - Diagonal Traverse
Diagonal Traverse (Medium): Given an m x n matrix , return all its elements in diagonal order . The diagonals are the… Topics: Array, Matrix, Simulation.
Medium - Distribute Coins in Binary Tree
Distribute Coins in Binary Tree (Medium): You are given the root of a binary tree with n nodes, where each node holds node.val coins. There… Topics: Tree, DFS.
Medium - Divide Two Integers
Divide Two Integers (Medium): Given two integers dividend and divisor , divide them without using multiplication, division, or… Topics: Math, Bit Manipulation.
Medium - Dot Product of Two Sparse Vectors
Dot Product of Two Sparse Vectors (Medium): Two vectors a and b of equal length are sparse : most of their entries… Topics: Array, Hash Table, Two Pointers.
Medium - Double a Number Represented as a Linked List
Double a Number Represented as a Linked List (Medium): Given the head of a non-empty linked list whose nodes store the… Topics: Linked List, Math, Stack.
Medium - Even Odd Tree
Even Odd Tree (Medium): A binary tree is even-odd if: on even-indexed levels (root is level 0) every node has an odd value and values are… Topics: Tree, BFS.
Medium - Factorial Trailing Zeroes
Factorial Trailing Zeroes (Medium): Given an integer n , return the number of trailing zeroes in n! (n factorial). Topics: Math.
Medium - Find All Anagrams in a String
Find All Anagrams in a String (Medium): Return the start index of every substring of s that is an anagram of t ,… Topics: String, Hash Table, Sliding Window.
Medium - Find Bottom Left Tree Value
Find Bottom Left Tree Value (Medium): Given the root of a binary tree, return the leftmost value in the last (deepest) row of the tree. Topics: Tree, BFS, DFS.
Medium - Find Champion II
Find Champion II (Medium): There are n teams labeled 0..n-1 in a tournament. Each directed edge [u, v] means team u is stronger than team v . A… Topics: Graph.
Medium - Find First and Last Position of Element in Sorted Array
Find First and Last Position of Element in Sorted Array (Medium): Given a sorted array nums and a target , return [first, last]… Topics: Array, Binary Search.
Medium - Find K Closest Elements
Find K Closest Elements (Medium): nums is sorted ascending. Return the k elements closest to x , in ascending… Topics: Array, Binary Search, Two Pointers.
Medium - Find Largest Value in Each Tree Row
Find Largest Value in Each Tree Row (Medium): Given the root of a binary tree, return an array containing the largest value in each row… Topics: Tree, BFS.
Medium - Find Leaves of Binary Tree
Find Leaves of Binary Tree (Medium): Given the root of a binary tree, collect its nodes as follows: take all the leaves and… Topics: Tree, DFS, Binary Tree.
Medium - Find Peak Element
Find Peak Element (Medium): A peak is an element that is strictly greater than both of its neighbours. Given a 0-indexed array… Topics: Array, Binary Search.
Medium - Find the Celebrity
Find the Celebrity (Medium): Among n people at a party, there may be one celebrity : somebody who everybody else… Topics: Two Pointers, Graph, Interactive.
Medium - Find the Length of the Longest Common Prefix
Find the Length of the Longest Common Prefix (Medium): You are given two arrays of positive integers, a and b . A common… Topics: Array, Hash Table, String.
Medium - Find the Smallest Divisor Given a Threshold
Find the Smallest Divisor Given a Threshold (Medium): Given an array nums and an integer target (the threshold), find the… Topics: Array, Binary Search.
Medium - Find the Winner of the Circular Game
Find the Winner of the Circular Game (Medium): a friends sit in a circle, numbered 1 to a clockwise. Starting at friend 1 ,… Topics: Array, Math, Recursion.
Medium - Flatten Binary Tree to Linked List
Flatten Binary Tree to Linked List (Medium): Given the root of a binary tree, flatten it into a linked list in place. The list… Topics: Tree, DFS, Linked List.
Medium - Flatten Nested List Iterator
Flatten Nested List Iterator (Medium): You are given a nested list of integers , where each element is either an integer or a list… Topics: Stack, Tree, DFS.
Medium - Frequency of the Most Frequent Element
Frequency of the Most Frequent Element (Medium): You may perform at most k operations, each of which adds 1 to any… Topics: Array, Binary Search, Greedy.
Medium - Fruit Into Baskets
Fruit Into Baskets (Medium): A row of fruit trees stands along a path, and fruits[i] is the kind of fruit tree i… Topics: Array, Hash Table, Sliding Window.
Medium - Game of Life
Game of Life (Medium): The board is an m x n grid of cells, each 1 (live) or 0 (dead). Every cell has up to eight… Topics: Array, Matrix, Simulation.
Medium - H-Index
H-Index (Medium): Given an array citations where citations[i] is the number of citations for the i-th paper, return the… Topics: Array, Sorting, Counting Sort.
Medium - H-Index II
H-Index II (Medium): Given an array nums of citation counts sorted in ascending order, return the researcher's h-index : the… Topics: Array, Binary Search.
Medium - Heaters
Heaters (Medium): Houses and heaters stand on a horizontal line. a holds the house positions and b holds the… Topics: Array, Two Pointers, Binary Search.
Medium - House Robber III
House Robber III (Medium): Houses are arranged as a binary tree. You cannot rob two directly-connected houses (a… Topics: Tree, DFS, Dynamic Programming.
Medium - Insertion Sort List
Insertion Sort List (Medium): Given the head of a singly linked list, sort it in ascending order using insertion sort and return… Topics: Linked List, Sorting.
Medium - Integer to Roman
Integer to Roman (Medium): Roman numerals are written by adding up symbols from largest to smallest: I 1, V 5, X 10, L 50, C… Topics: Hash Table, Math, String.
Medium - Kth Smallest Element in a Sorted Matrix
Kth Smallest Element in a Sorted Matrix (Medium): grid is an n by n matrix with every row sorted ascending and every… Topics: Array, Binary Search, Heap.
Medium - Largest Number
Largest Number (Medium): Given a list of non-negative integers nums , arrange them so that their concatenation forms the… Topics: Array, String, Greedy.
Medium - Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit
Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit (Medium): Given an integer array nums and a non-negative integer limit , find the…
Medium - Longest Palindromic Subsequence
Longest Palindromic Subsequence (Medium): A subsequence is what remains after deleting any number of characters without… Topics: String, Dynamic Programming.
Medium - Longest String Chain
Longest String Chain (Medium): wordA is a predecessor of wordB if inserting exactly one letter anywhere in wordA ,… Topics: Array, Hash Table, Two Pointers.
Medium - Longest Substring with At Most K Distinct Characters
Longest Substring with At Most K Distinct Characters (Medium): Given a string s and an integer k , return the… Topics: String, Sliding Window, Hash Table.
Medium - Longest Univalue Path
Longest Univalue Path (Medium): Given the root of a binary tree, return the length of the longest path where every node on the path has the… Topics: Tree, DFS.
Medium - Lowest Common Ancestor of a Binary Tree
Lowest Common Ancestor of a Binary Tree (Medium): You are given the root of a binary tree whose node values are all different, plus two… Topics: Tree, DFS.
Medium - Lowest Common Ancestor of a Binary Tree II
Lowest Common Ancestor of a Binary Tree II (Medium): Given the root of a binary tree with distinct node values, and two values… Topics: Hash Table, Tree, DFS.
Medium - Magnetic Force Between Two Balls
Magnetic Force Between Two Balls (Medium): Given an array nums of distinct basket positions and an integer target (= m… Topics: Array, Binary Search, Sorting.
Medium - Majority Element II
Majority Element II (Medium): Given an integer array nums of size n, return all elements that appear more than… Topics: Array, Hash Table, Sorting.
Medium - Max Consecutive Ones III
Max Consecutive Ones III (Medium): Given a binary array nums and an integer target (the number of 0 s you may flip to 1 ),… Topics: Array, Sliding Window.
Medium - Maximal Network Rank
Maximal Network Rank (Medium): There are n cities and some undirected roads given as edges . The network rank of two different cities is… Topics: Graph, Array.
Medium - Maximal Square
Maximal Square (Medium): Given an m x n binary grid filled with 0 s and 1 s, find the largest square containing… Topics: Array, Dynamic Programming, Matrix.
Medium - Maximize Distance to Closest Person
Maximize Distance to Closest Person (Medium): nums describes a row of seats, where 1 is occupied and 0 is empty. There is at least one of each.… Topics: Array.
Medium - Maximum Candies Allocated to K Children
Maximum Candies Allocated to K Children (Medium): Given an array nums of candy piles and an integer target (= k children), split… Topics: Array, Binary Search.
Medium - Maximum Number of Events That Can Be Attended
Maximum Number of Events That Can Be Attended (Medium): Each row of grid is an event [startDay, endDay] , meaning that event can… Topics: Array, Greedy, Heap.
Medium - Maximum Palindromes After Operations
Maximum Palindromes After Operations (Medium): You may repeatedly pick any two positions in any two words of words — the… Topics: Array, String, Hash Table.
Medium - Maximum Points You Can Obtain from Cards
Maximum Points You Can Obtain from Cards (Medium): nums is a row of cards with a value on each. In one step you… Topics: Array, Sliding Window, Prefix Sum.
Medium - Maximum Size Subarray Sum Equals k
Maximum Size Subarray Sum Equals k (Medium): Given an integer array nums and an integer k , return the maximum length… Topics: Array, Hash Table, Prefix Sum.
Medium - Maximum Sum Circular Subarray
Maximum Sum Circular Subarray (Medium): nums is circular : the element after the last one is the first… Topics: Array, Divide and Conquer, Dynamic Programming.
Medium - Maximum Swap
Maximum Swap (Medium): Given a non-negative integer n , you may swap two digits at most once to get the maximum valued number. Return… Topics: Math, Greedy.
Medium - Maximum Width of Binary Tree
Maximum Width of Binary Tree (Medium): Given the root of a binary tree, return the maximum width . The width of a level is the number of… Topics: Tree, BFS.
Medium - Maximum XOR of Two Numbers in an Array
Maximum XOR of Two Numbers in an Array (Medium): Given an integer array nums , return the maximum result of nums[i] XOR… Topics: Array, Bit Manipulation, Trie.
Medium - Merge Nodes in Between Zeros
Merge Nodes in Between Zeros (Medium): You are given the head of a linked list that begins and ends with 0 ; between every… Topics: Linked List, Simulation.
Medium - Minimized Maximum of Products Distributed to Any Store
Minimized Maximum of Products Distributed to Any Store (Medium): You have n product types. The i th type has nums[i] units in… Topics: Array, Binary Search.
Medium - Minimum Add to Make Parentheses Valid
Minimum Add to Make Parentheses Valid (Medium): Given a parentheses string s , return the minimum number of ( or ) insertions… Topics: String, Stack, Greedy.
Medium - Minimum Cost For Tickets
Minimum Cost For Tickets (Medium): a lists the days of the year you will travel, in strictly increasing order. b holds… Topics: Array, Dynamic Programming.
Medium - Minimum Knight Moves
Minimum Knight Moves (Medium): On an infinite chessboard with coordinates from -infinity to +infinity , a knight starts at square [0, 0] .… Topics: BFS, Math.
Medium - Minimum Limit of Balls in a Bag
Minimum Limit of Balls in a Bag (Medium): Given an array nums of bag sizes and an integer target (the maximum number of split… Topics: Array, Binary Search.
Medium - Minimum Moves to Equal Array Elements
Minimum Moves to Equal Array Elements (Medium): Given an array nums , in one move you may increment n - 1 elements by 1. Return… Topics: Array, Math, Greedy.
Medium - Minimum Number of Arrows to Burst Balloons
Minimum Number of Arrows to Burst Balloons (Medium): There are some spherical balloons taped onto a flat wall. The balloons… Topics: Array, Greedy, Sorting.
Medium - Minimum Number of Days to Make m Bouquets
Minimum Number of Days to Make m Bouquets (Medium): nums[i] is the day flower i blooms. You want a bouquets, and each bouquet… Topics: Array, Binary Search.
Medium - Minimum Number of Steps to Make Two Strings Anagram
Minimum Number of Steps to Make Two Strings Anagram (Medium): s and t have the same length . In one step you may replace… Topics: String, Hash Table, Counting.
Medium - Minimum Number of Swaps to Make the String Balanced
Minimum Number of Swaps to Make the String Balanced (Medium): s has an even length and holds only the characters [ and ] , with… Topics: String, Stack, Greedy.
Medium - Minimum Path Sum
Minimum Path Sum (Medium): Given an m x n grid filled with non-negative numbers, find a path from the top-left to… Topics: Array, Dynamic Programming, Matrix.
Medium - Minimum Remove to Make Valid Parentheses
Minimum Remove to Make Valid Parentheses (Medium): Given a string s of lowercase letters and the characters ( and ) , remove the… Topics: String, Stack.
Medium - Minimum Size Subarray Sum
Minimum Size Subarray Sum (Medium): Given an array of positive integers nums and a positive integer target ,… Topics: Array, Sliding Window, Two Pointers.
Medium - Minimum Time to Complete Trips
Minimum Time to Complete Trips (Medium): Given an array nums where nums[i] is the time a bus takes for one trip, and an integer… Topics: Array, Binary Search.
Medium - Most Stones Removed with Same Row or Column
Most Stones Removed with Same Row or Column (Medium): On a 2D plane, we place n stones at some integer coordinate points. Each… Topics: Union Find, Graph, DFS.
Medium - Nested List Weight Sum
Nested List Weight Sum (Medium): You are given a nested list of integers . Each element is either an integer or a list whose elements… Topics: DFS, BFS, Stack.
Medium - Next Greater Element II
Next Greater Element II (Medium): Given a circular array nums , return an array where each position holds the next… Topics: Array, Stack, Monotonic Stack.
Medium - Next Permutation
Next Permutation (Medium): Rearrange nums into the lexicographically next greater permutation. If no greater permutation exists,… Topics: Array, Two Pointers.
Medium - Number of Closed Islands
Number of Closed Islands (Medium): Given a grid where 0 is land and 1 is water, an island is a maximal group of 4-directionally… Topics: Graph, DFS, BFS.
Medium - Number of Distinct Islands
Number of Distinct Islands (Medium): You are given an m x n binary matrix grid . An island is a group of 1 s connected… Topics: Array, Hash Table, DFS.
Medium - Number of Divisible Triplet Sums
Number of Divisible Triplet Sums (Medium): Given a 0-indexed integer array nums and an integer k , return the number of index… Topics: Array, Hash Table.
Medium - Number of Enclaves
Number of Enclaves (Medium): Given a binary grid where 1 is land and 0 is sea, return the number of land cells from which you cannot… Topics: Graph, DFS, BFS.
Medium - Number of Provinces
Number of Provinces (Medium): There are n cities. You are given an n x n matrix grid where grid[i][j] = 1 means city i and city j are… Topics: Graph, DFS, BFS.
Medium - Odd Even Linked List
Odd Even Linked List (Medium): Given the head of a singly linked list, group all the nodes at odd positions together followed by the… Topics: Linked List.
Medium - One Edit Distance
One Edit Distance (Medium): Given two strings s and t , return true if they are exactly one edit distance apart . One edit means… Topics: Two Pointers, String.
Medium - Open the Lock
Open the Lock (Medium): A lock has four wheels, each showing a digit 0 to 9 . One turn moves a single wheel one step, and… Topics: Array, String, Hash Table.
Medium - Paint House
Paint House (Medium): There is a row of n houses, each to be painted one of three colours: red, blue or green. Painting… Topics: Array, Dynamic Programming.
Medium - Parallel Courses
Parallel Courses (Medium): You are given n courses labelled 0 to n - 1 and a list of edges where edges[i] = [a, b] means… Topics: Graph, Topological Sort, BFS.
Medium - Partition Equal Subset Sum
Partition Equal Subset Sum (Medium): Given an array nums of positive integers, return true if it can be split into two… Topics: Array, Dynamic Programming.
Medium - Partition List
Partition List (Medium): Given the head of a linked list and a value k , partition it so that all nodes with value less… Topics: Linked List, Two Pointers.
Medium - Path Sum III
Path Sum III (Medium): Given the root of a binary tree and an integer targetSum (passed as k ), return the number of downward… Topics: Tree, DFS, Prefix Sum.
Medium - Path With Minimum Effort
Path With Minimum Effort (Medium): You are given a grid heights of size rows x columns . You start at the top-left… Topics: Array, Binary Search, Union Find.
Medium - Peak Index in a Mountain Array
Peak Index in a Mountain Array (Medium): An array nums is a mountain : it strictly increases up to a unique peak and then… Topics: Array, Binary Search.
Medium - Perfect Squares
Perfect Squares (Medium): Return the fewest perfect squares that add up to n . A perfect square is an integer times… Topics: Math, Dynamic Programming, BFS.
Medium - Possible Bipartition
Possible Bipartition (Medium): n people are numbered 1 to n . Each row of edges is a pair [a, b] meaning those two people dislike… Topics: Graph, BFS, DFS.
Medium - Pseudo-Palindromic Paths in a Binary Tree
Pseudo-Palindromic Paths in a Binary Tree (Medium): Node values are digits 1-9 . A root-to-leaf path is… Topics: Tree, DFS, Bit Manipulation.
Medium - Remove All Adjacent Duplicates in String II
Remove All Adjacent Duplicates in String II (Medium): A k-duplicate removal deletes k adjacent equal characters from s , closing the… Topics: String, Stack.
Medium - Remove All Occurrences of a Substring
Remove All Occurrences of a Substring (Medium): Repeat the following until s no longer contains t : find the leftmost… Topics: String, Stack, Simulation.
Medium - Remove Duplicate Letters
Remove Duplicate Letters (Medium): Given a string s , remove duplicate letters so that every letter appears exactly once .… Topics: String, Stack, Greedy.
Medium - Remove Duplicates from Sorted List II
Remove Duplicates from Sorted List II (Medium): Given the head of a sorted linked list, delete all nodes that have… Topics: Linked List, Two Pointers.
Medium - Remove K Digits
Remove K Digits (Medium): Given a string s of digits representing a non-negative integer, remove exactly k digits so that the… Topics: String, Stack, Greedy.
Medium - Remove Nodes From Linked List
Remove Nodes From Linked List (Medium): Given the head of a linked list, remove every node which has a node with a… Topics: Linked List, Stack, Recursion.
Medium - Removing Stars From a String
Removing Stars From a String (Medium): Given a string s with letters and * . Each * removes the closest non-star character to its left… Topics: String, Stack.
Medium - Reorganize String
Reorganize String (Medium): Rearrange the characters of s so that no two adjacent characters are the same . If no such… Topics: Hash Table, String, Greedy.
Medium - Restore IP Addresses
Restore IP Addresses (Medium): A valid IP address is four numbers separated by dots, where each number is between 0 and 255 and… Topics: String, Backtracking.
Medium - Restore the Array From Adjacent Pairs
Restore the Array From Adjacent Pairs (Medium): There is an array of n distinct integers that you do not have. What you have is… Topics: Array, Hash Table.
Medium - Reverse Words in a String
Reverse Words in a String (Medium): Given an input string s , reverse the order of the words. Words are separated by one or more… Topics: String, Two Pointers.
Medium - Rotate Array
Rotate Array (Medium): Given an array nums , rotate it to the right by k steps ( k passed as target ) and return the rotated array. Topics: Array, Two Pointers.
Medium - Rotate List
Rotate List (Medium): Given the head of a linked list, rotate the list to the right by k places and return the new head. Topics: Linked List, Two Pointers.
Medium - Score of Parentheses
Score of Parentheses (Medium): Given a balanced parentheses string s , compute its score: () is 1, AB is A+B, and (A) is 2*A. Topics: String, Stack.
Medium - Search a 2D Matrix II
Search a 2D Matrix II (Medium): matrix has every row sorted ascending left to right, and every column sorted… Topics: Array, Binary Search, Divide and Conquer.
Medium - Second Highest Salary
Second Highest Salary (Medium): Given an array of salaries nums , return the second highest distinct salary, or -1 if there is no such… Topics: Array, Sorting.
Medium - Shortest Bridge
Shortest Bridge (Medium): You are given an n x n binary grid containing exactly two islands. An island is a group of 1 s connected… Topics: Array, DFS, BFS.
Medium - Shortest Path in Binary Matrix
Shortest Path in Binary Matrix (Medium): Given a binary matrix grid , return the length of the shortest clear path from the… Topics: Graph, BFS, Matrix.
Medium - Simple Bank System
Simple Bank System (Medium): You are given an array balance where balance[i] is the starting balance of account i + 1 —… Topics: Array, Hash Table, Design.
Medium - Simplify Path
Simplify Path (Medium): Given an absolute Unix-style path path , return its simplified canonical path. Handle . (current), .. (parent),… Topics: String, Stack.
Medium - Single Element in a Sorted Array
Single Element in a Sorted Array (Medium): Given a sorted array nums where every element appears exactly twice except for one… Topics: Array, Binary Search.
Medium - Single Number II
Single Number II (Medium): Every element in nums appears exactly three times except for one, which appears once. Return that… Topics: Array, Bit Manipulation.
Medium - Single Number III
Single Number III (Medium): Given an array nums in which exactly two elements appear only once and all the others appear… Topics: Array, Bit Manipulation.
Medium - Snakes and Ladders
Snakes and Ladders (Medium): grid is an n by n board whose squares are numbered 1 to n * n in boustrophedon order: starting at the… Topics: Array, BFS, Matrix.
Medium - Snapshot Array
Snapshot Array (Medium): Implement an array-like structure that can take snapshots and be read back at any earlier… Topics: Array, Hash Table, Binary Search.
Medium - Sort Characters By Frequency
Sort Characters By Frequency (Medium): Given a string s , rearrange its characters so that the most frequent character… Topics: String, Hash Table, Sorting.
Medium - Sort Colors
Sort Colors (Medium): Given an array nums with n objects colored red, white, or blue ( 0 , 1 , 2 ), sort them in-place… Topics: Array, Two Pointers, Sorting.
Medium - Sort List
Sort List (Medium): Given the head of a linked list, return the list sorted in ascending order. Topics: Linked List, Sorting, Merge Sort.
Medium - Stone Game
Stone Game (Medium): Alice and Bob play a game with piles of stones arranged in a row. The i -th pile has… Topics: Array, Dynamic Programming, Game Theory.
Medium - String Compression
String Compression (Medium): Shorten a string of letters by run-length encoding. Split s into maximal runs of the same… Topics: String, Two Pointers.
Medium - String to Integer (atoi)
String to Integer (atoi) (Medium): Turn the text s into a 32-bit signed integer by reading it strictly left to right: Skip any leading space… Topics: String.
Medium - Subarray Product Less Than K
Subarray Product Less Than K (Medium): Given an array of positive integers nums and an integer k , return the… Topics: Array, Sliding Window, Two Pointers.
Medium - Subarray Sum Equals K
Subarray Sum Equals K (Medium): Given an integer array nums and an integer k (passed as target ), return the total… Topics: Array, Hash Table, Prefix Sum.
Medium - Sum of Nodes with Even-Valued Grandparent
Sum of Nodes with Even-Valued Grandparent (Medium): Given the root of a binary tree, return the sum of values of every node whose… Topics: Tree, DFS, BFS.
Medium - Sum of Subarray Minimums
Sum of Subarray Minimums (Medium): Given an array nums , find the minimum of every contiguous subarray and return… Topics: Array, Dynamic Programming, Stack.
Medium - Sum Root to Leaf Numbers
Sum Root to Leaf Numbers (Medium): Each root-to-leaf path in a binary tree represents a number formed by concatenating the node digits… Topics: Tree, DFS.
Medium - Swap Nodes in Pairs
Swap Nodes in Pairs (Medium): Given the head of a linked list, swap every two adjacent nodes and return its head. You must… Topics: Linked List, Recursion.
Medium - Swapping Nodes in a Linked List
Swapping Nodes in a Linked List (Medium): Given the head of a linked list and an integer k , swap the values of the k -th… Topics: Linked List, Two Pointers.
Medium - Top K Frequent Words
Top K Frequent Words (Medium): Given an array of strings words and an integer k , return the k most frequent words. The… Topics: Array, String, Hash Table.
Medium - Unique Paths II
Unique Paths II (Medium): A robot starts at the top-left cell of grid and wants to reach the bottom-right cell,… Topics: Array, Dynamic Programming, Matrix.
Medium - Wiggle Subsequence
Wiggle Subsequence (Medium): A wiggle sequence has strictly alternating positive and negative differences between… Topics: Array, Dynamic Programming, Greedy.
Medium - Zigzag Conversion
Zigzag Conversion (Medium): Write s downwards across k rows, then diagonally back up to the first row, then downwards again, and so on — a… Topics: String.
Medium - Basic Calculator
Basic Calculator (Hard): Given a string s representing a valid expression, implement a basic calculator to evaluate it and return… Topics: Math, String, Stack.
Hard - Best Meeting Point
Best Meeting Point (Hard): Given an m x n binary grid where each 1 marks the home of a friend, return the minimal total travel… Topics: Array, Math, Sorting.
Hard - Best Time to Buy and Sell Stock III
Best Time to Buy and Sell Stock III (Hard): Given an array prices where prices[i] is the stock price on day i , return the… Topics: Array, Dynamic Programming.
Hard - Best Time to Buy and Sell Stock IV
Best Time to Buy and Sell Stock IV (Hard): You are given an integer array nums where nums[i] is the price of a stock on… Topics: Array, Dynamic Programming.
Hard - Binary Tree Cameras
Binary Tree Cameras (Hard): You are given the root of a binary tree. A camera placed on a node can monitor its parent,… Topics: Tree, DFS, Dynamic Programming.
Hard - Candy
Candy (Hard): There are n children with ratings . Each child gets at least one candy, and a child with a higher rating than an adjacent… Topics: Array, Greedy.
Hard - Cherry Pickup
Cherry Pickup (Hard): You are given an n x n grid where each cell is 0 (empty), 1 (a cherry), or -1 (a thorn you… Topics: Array, Dynamic Programming, Matrix.
Hard - Cherry Pickup II
Cherry Pickup II (Hard): Given a grid where each cell holds a number of cherries, two robots start at the top-left… Topics: Array, Dynamic Programming, Matrix.
Hard - Consecutive Numbers Sum
Consecutive Numbers Sum (Hard): Given an integer n , return the number of ways to write it as a sum of consecutive positive integers. Topics: Math.
Hard - Constrained Subsequence Sum
Constrained Subsequence Sum (Hard): Given an integer array nums and an integer target (= k), return the maximum sum… Topics: Array, Dynamic Programming, Queue.
Hard - Count Different Palindromic Subsequences
Count Different Palindromic Subsequences (Hard): Given a string s , return the number of different non-empty palindromic… Topics: String, Dynamic Programming.
Hard - Count Different Palindromic Subsequences
Count Different Palindromic Subsequences (Hard): Given a string s , count the different non-empty palindromic… Topics: String, Dynamic Programming.
Hard - Count of Smaller Numbers After Self
Count of Smaller Numbers After Self (Hard): Given an integer array nums , return an array counts where… Topics: Array, Binary Indexed Tree, Segment Tree.
Hard - Count Subarrays With Fixed Bounds
Count Subarrays With Fixed Bounds (Hard): A subarray is fixed-bound when its minimum is exactly a and its maximum is… Topics: Array, Queue, Sliding Window.
Hard - Cut Off Trees for Golf Event
Cut Off Trees for Golf Event (Hard): You are given a grid where 0 is an impassable obstacle, 1 is walkable ground, and any value… Topics: Array, BFS, Matrix.
Hard - Distinct Echo Substrings
Distinct Echo Substrings (Hard): Return the number of distinct non-empty substrings of s that can be written as the… Topics: String, Hash Table, Rolling Hash.
Hard - Divide Chocolate
Divide Chocolate (Hard): Given an array nums of chunk sweetness values and an integer target (the number of cuts), you split the… Topics: Array, Binary Search.
Hard - Dungeon Game
Dungeon Game (Hard): A knight starts at the top-left cell of grid and must reach the bottom-right cell, moving… Topics: Array, Dynamic Programming, Matrix.
Hard - Encode String with Shortest Length
Encode String with Shortest Length (Hard): Given a string s , encode it so that its encoded length is as short as… Topics: String, Dynamic Programming.
Hard - Find in Mountain Array
Find in Mountain Array (Hard): An array is a mountain array if there is some index peak with 0 peak n - 1 such that nums[0]… Topics: Array, Binary Search.
Hard - Find K-th Smallest Pair Distance
Find K-th Smallest Pair Distance (Hard): The distance of a pair (a, b) is |a - b| . Given an integer array nums… Topics: Array, Two Pointers, Binary Search.
Hard - First Missing Positive
First Missing Positive (Hard): Given an unsorted array nums , return the smallest missing positive integer. Aim for O(n) time and… Topics: Array, Hash Table.
Hard - Frog Jump
Frog Jump (Hard): A frog crosses a river by hopping on stones. The array nums gives the sorted positions of… Topics: Array, Dynamic Programming, Hash Table.
Hard - Integer Replacement
Integer Replacement (Hard): Given a positive integer n , in one operation you may replace n by n / 2 if it is even, or… Topics: Math, Bit Manipulation, Greedy.
Hard - Integer to English Words
Integer to English Words (Hard): Convert a non-negative integer n to its English words representation. Words are separated by… Topics: Math, String, Recursion.
Hard - IPO
IPO (Hard): You are given a list of projects where projects[i] = [profit, capital] , an integer k , and a starting capital w .… Topics: Array, Greedy, Heap.
Hard - Jump Game IV
Jump Game IV (Hard): Given an integer array nums , you start at index 0. From index i you can move to i+1 , i-1 , or any index… Topics: Array, BFS, Hash Table.
Hard - Largest Multiple of Three
Largest Multiple of Three (Hard): Given an array nums of digits (each 0-9), form the largest possible multiple of… Topics: Array, Dynamic Programming, Greedy.
Hard - LFU Cache
LFU Cache (Hard): Design a cache that evicts the least frequently used key when it is full. LFUCache(capacity)… Topics: Hash Table, Linked List, Design.
Hard - Longest Cycle in a Graph
Longest Cycle in a Graph (Hard): You are given a directed graph of n nodes numbered from 0 to n - 1 , where each node has at most one… Topics: Graph, DFS.
Hard - Longest Duplicate Substring
Longest Duplicate Substring (Hard): Given a string s , consider all duplicated substrings : (contiguous)… Topics: String, Binary Search, Suffix Array.
Hard - Longest Valid Parentheses
Longest Valid Parentheses (Hard): Given a string s containing just the characters '(' and ')' , return the length… Topics: String, Dynamic Programming, Stack.
Hard - Longest ZigZag Path in a Binary Tree
Longest ZigZag Path in a Binary Tree (Hard): A ZigZag path alternates direction (left, right, left, ...) at each step.… Topics: Tree, DFS, Dynamic Programming.
Hard - Making A Large Island
Making A Large Island (Hard): You are given an n x n binary grid. You may change at most one 0 to a 1 . Return the size of the… Topics: Array, DFS, BFS.
Hard - Matchsticks to Square
Matchsticks to Square (Hard): You are given an array nums where nums[i] is the length of the i-th matchstick. You must… Topics: Array, Backtracking, Bitmask.
Hard - Max Points on a Line
Max Points on a Line (Hard): You are given grid , where each row is a distinct point [x, y] on the plane. Return the maximum… Topics: Array, Hash Table, Math.
Hard - Max Stack
Max Stack (Hard): Design a stack that supports finding and removing the maximum element. Implement MaxStack() and: push(x)… Topics: Stack, Design, Sorted Set.
Hard - Maximal Rectangle
Maximal Rectangle (Hard): Given a rows-of-characters binary matrix grid filled with '0' and '1' , find the largest… Topics: Array, Dynamic Programming, Stack.
Hard - Maximum Gap
Maximum Gap (Hard): Given an integer array nums , return the maximum difference between two successive elements once the… Topics: Array, Sorting, Bucket Sort.
Hard - Maximum Number of Points with Cost
Maximum Number of Points with Cost (Hard): You are given an m x n matrix points . You pick exactly one cell in… Topics: Array, Dynamic Programming, Matrix.
Hard - Maximum Performance of a Team
Maximum Performance of a Team (Hard): You are given k , and two arrays speed and efficiency of equal length describing engineers.… Topics: Array, Greedy, Heap.
Hard - Maximum Profit in Job Scheduling
Maximum Profit in Job Scheduling (Hard): You are given n jobs, each described by a row [start, end, profit]… Topics: Array, Dynamic Programming, Binary Search.
Hard - Maximum Sum BST in Binary Tree
Maximum Sum BST in Binary Tree (Hard): Given the root of a binary tree, return the maximum sum of all keys of any… Topics: Tree, DFS, Binary Search Tree.
Hard - Minimize Deviation in Array
Minimize Deviation in Array (Hard): Given an array nums of positive integers, you may repeatedly apply two operations any number… Topics: Array, Greedy, Heap.
Hard - Minimum Cost to Hire K Workers
Minimum Cost to Hire K Workers (Hard): There are n workers. Worker i has quality nums[i] (first n/2 of the array) and minimum… Topics: Array, Greedy, Sorting.
Hard - Minimum Cost to Make at Least One Valid Path in a Grid
Minimum Cost to Make at Least One Valid Path in a Grid (Hard): Each cell of the grid holds a sign pointing to the next cell you… Topics: Array, BFS, Graph.
Hard - Minimum Cost to Merge Stones
Minimum Cost to Merge Stones (Hard): You have nums.length piles of stones arranged in a row; nums[i] is the… Topics: Array, Dynamic Programming, Prefix Sum.
Hard - Minimum Falling Path Sum II
Minimum Falling Path Sum II (Hard): Given an n x n integer grid , a falling path with non-zero shifts chooses… Topics: Array, Dynamic Programming, Matrix.
Hard - Minimum Height Trees
Minimum Height Trees (Hard): Given a tree of n nodes labeled from 0 to n-1 with n-1 edges, return the number of nodes… Topics: Graph, BFS, Topological Sort.
Hard - Minimum Number of K Consecutive Bit Flips
Minimum Number of K Consecutive Bit Flips (Hard): You are given a binary array nums and an integer target… Topics: Array, Bit Manipulation, Sliding Window.
Hard - Minimum Number of Taps to Open to Water a Garden
Minimum Number of Taps to Open to Water a Garden (Hard): A garden is a one-dimensional interval [0, k] . There are… Topics: Array, Dynamic Programming, Greedy.
Hard - My Calendar III
My Calendar III (Hard): You are given a list of bookings where bookings[i] = [start, end] represents a half-open… Topics: Array, Sweep Line, Segment Tree.
Hard - N-Queens II
N-Queens II (Hard): The n-queens puzzle places n queens on an n x n chessboard so that no two queens attack each other (no shared row,… Topics: Backtracking.
Hard - Number of Atoms
Number of Atoms (Hard): Given a chemical formula (as string s ), return the count of each atom. Output the element names in… Topics: Hash Table, String, Stack.
Hard - Number of Good Leaf Nodes Pairs
Number of Good Leaf Nodes Pairs (Hard): Given the root of a binary tree and an integer distance , a pair of two different leaf nodes is… Topics: Tree, DFS.
Hard - Number of Visible People in a Queue
Number of Visible People in a Queue (Hard): nums holds the heights of people standing in a queue, all facing to the… Topics: Array, Stack, Monotonic Stack.
Hard - Numbers With Repeated Digits
Numbers With Repeated Digits (Hard): Given an integer n , return the count of positive integers in the range [1, n] that… Topics: Math, Dynamic Programming.
Hard - Optimal Account Balancing
Optimal Account Balancing (Hard): You are given an array of transactions where transactions[i] = [from, to,… Topics: Array, Dynamic Programming, Backtracking.
Hard - Palindrome Partitioning II
Palindrome Partitioning II (Hard): Given a string s , partition it so that every substring of the partition is a… Topics: String, Dynamic Programming.
Hard - Predict the Winner
Predict the Winner (Hard): Given a score array nums , two players take turns picking a number from either end; the… Topics: Array, Math, Dynamic Programming.
Hard - Redundant Connection II
Redundant Connection II (Hard): A rooted tree is a directed graph where every node has exactly one parent except the root,… Topics: Graph, Union Find, Tree.
Hard - Reverse Pairs
Reverse Pairs (Hard): Given an integer array nums , return the number of reverse pairs . A reverse pair is a… Topics: Array, Merge Sort, Binary Indexed Tree.
Hard - Russian Doll Envelopes
Russian Doll Envelopes (Hard): You are given a list grid of envelopes where grid[i] = [w, h] is the width… Topics: Array, Binary Search, Dynamic Programming.
Hard - Scramble String
Scramble String (Hard): We can scramble a string s by recursively splitting it into two non-empty substrings and… Topics: String, Dynamic Programming.
Hard - Self Crossing
Self Crossing (Hard): You start at the origin and move counter-clockwise: nums[0] north, nums[1] west, nums[2] south, nums[3]… Topics: Array, Math, Geometry.
Hard - Shortest Distance from All Buildings
Shortest Distance from All Buildings (Hard): You are given a grid where 0 is empty land you can travel through, 1 marks a… Topics: Array, BFS, Matrix.
Hard - Shortest Palindrome
Shortest Palindrome (Hard): You are given a string s . You may convert it to a palindrome by adding characters… Topics: String, Rolling Hash, String Matching.
Hard - Shortest Path in a Grid with Obstacles Elimination
Shortest Path in a Grid with Obstacles Elimination (Hard): grid holds 0 for an empty cell and 1 for an obstacle. You start at the… Topics: Array, BFS, Matrix.
Hard - Shortest Subarray with Sum at Least K
Shortest Subarray with Sum at Least K (Hard): Given an integer array nums and an integer target , return the length… Topics: Array, Prefix Sum, Sliding Window.
Hard - Special Binary String
Special Binary String (Hard): A binary string is special when it has equal numbers of 0 s and 1 s, and every… Topics: String, Recursion, Divide and Conquer.
Hard - Split Array Largest Sum
Split Array Largest Sum (Hard): Given an array nums and an integer target (= k), split nums into target non-empty… Topics: Array, Binary Search, Greedy.
Hard - Stone Game II
Stone Game II (Hard): Alice and Bob play with piles of stones nums (pile i has nums[i] stones). Alice moves first… Topics: Array, Math, Dynamic Programming.
Hard - Stone Game III
Stone Game III (Hard): Given nums (the value of each stone in a row), Alice and Bob alternate turns with Alice… Topics: Array, Math, Dynamic Programming.
Hard - Subarrays with K Different Integers
Subarrays with K Different Integers (Hard): Given an integer array nums and an integer target (= k), return the… Topics: Array, Hash Table, Sliding Window.
Hard - Sudoku Solver
Sudoku Solver (Hard): Fill a 9 by 9 Sudoku grid so that every row, every column, and each of the nine 3 by 3 boxes… Topics: Array, Backtracking, Matrix.
Hard - Super Egg Drop
Super Egg Drop (Hard): You are given a identical eggs and access to a building with b floors. An egg breaks… Topics: Math, Binary Search, Dynamic Programming.
Hard - Text Justification
Text Justification (Hard): Given an array of words and a width maxWidth , format the text so that every line has exactly… Topics: Array, String, Simulation.
Hard - Text Justification Line Count
Text Justification Line Count (Hard): Given an array of words nums (encoded as lengths) and a max width target , pack words… Topics: Array, String, Greedy.
Hard - The Skyline Problem
The Skyline Problem (Hard): You are given buildings where buildings[i] = [left, right, height] describes a rectangle standing… Topics: Array, Sweep Line, Heap.
Hard - Trapping Rain Water II
Trapping Rain Water II (Hard): Given an m x n matrix of non-negative integers representing the height of each cell, return the… Topics: Array, BFS, Heap.
Hard - Ugly Number II
Ugly Number II (Hard): An ugly number is a positive integer whose prime factors are limited to 2 , 3 , and 5 .… Topics: Hash Table, Math, Dynamic Programming.
Hard - Valid Number
Valid Number (Hard): Given a string s , return true if s is a valid number. A valid number has an optional sign, an integer or decimal part… Topics: String.
Hard - Vertical Order Traversal of a Binary Tree
Vertical Order Traversal of a Binary Tree (Hard): Give the root column 0 ; a left child sits one column left of its parent and… Topics: Hash Table, Tree, DFS.
Hard - Wildcard Matching
Wildcard Matching (Hard): Given an input string s and a pattern p , return true if p matches the entire s . The… Topics: String, Dynamic Programming, Greedy.
Hard
No results
No Problems entries are available.
Solve in your browser — pick a language, implement the function, and Submit for an instant verdict. Progress saves automatically to your profile.