Algorithm Problem Classification

Array/String [112]

Simple Pointers [39]

  • 26 Remove Duplicates from Sorted Array

  • 80 Remove Duplicates from Sorted Array II

  • 27 Remove Element

  • 283 Move Zeroes

  • 42 Trapping Rain Water

  • 238 Product of Array Except Self

  • *135 Candy

  • 209 Minimum Size Subarray Sum

  • *228 Summary Ranges

  • 163 Missing Ranges (Premium)

  • 56 Merge Intervals

  • 57 Insert Interval

  • 763 Partition Labels

  • *833. Find And Replace in String

  • *731 My Calendar II

  • 161 One Edit Distance (Premium)

  • 88 Merge Sorted Array

  • 392 Is Subsequence

  • 844 Backspace String Compare

  • *686 Repeated String Match

  • 11 Container With Most Water

  • 345 Reverse Vowels of a String

  • 125 Valid Palindrome

  • *680 Valid Palindrome II

  • 243 Shortest Word Distance (Premium)

  • 244 Shortest Word Distance II (Premium)

  • 245 Shortest Word Distance III (Premium)

  • 349 Intersection of Two Arrays

  • 350 Intersection of Two Arrays II

  • 15 3Sum

  • 16 3Sum Closest

  • 18 4Sum

  • 167 Two Sum II - Input Array Is Sorted

  • 170 Two Sum III - Data structure design (Premium)

  • 280 Wiggle Sort (Premium)

    *281 Wiggle Sort

  • *376 Wiggle Subsequence

  • 14 Longest Common Prefix

  • *31 Next Permutation

  • 418 Sentence Screen Fitting (Premium)

Binary Search [14]

  • 35 Search Insert Position

  • *4 Median of Two Sorted Arrays

  • 153 Find Minimum in Rotated Sorted Array

  • 154 Find Minimum in Rotated Sorted Array II

  • 34 Find First and Last Position of Element in Sorted Array

  • 374 Guess Number Higher or Lower

  • 278 First Bad Version

  • 33 Search in Rotated Sorted Array

  • 81 Search in Rotated Sorted Array II

  • *300 Longest Increasing Subsequence

  • *315 Count of Smaller Numbers After Self

  • *354 Russian Doll Envelopes

  • 274 H-Index

  • 275 H-Index II

    HashMap [5]

  • 242 Valid Anagram

  • 249 Group Shifted Strings (Premium)

  • *336 Palindrome Pairs

  • 356 Line Reflection (Premium)

  • *205 Isomorphic Strings

    1. Word Pattern
  • 1 Two Sum
  • 325 Maximum Size Subarray Sum Equals k (Premium)
  • 560 Subarray Sum Equals K

HashMap–Tracking [6]

  • 3 Longest Substring Without Repeating Characters
  • Longest Substring with At Most K Distinct Characters (Google)
  • *30 Substring with Concatenation of All Words
  • 76 Minimum Window Substring
  • *395 Longest Substring with At Least K Repeating Characters
  • 567 Permutation in String

HashSet [1]

  • *128 Longest Consecutive Sequence

Caching [4]

  • 169 Majority Element
  • *229 Majority Element II
  • *334 Increasing Triplet Subsequence
  • Find the 2nd Largest Elements in an array
    1. Kth Largest Element in an Array

BFS [2]

  • 127 Word Ladder
  • *126 Word Ladder I

Heap [8]

  • 347 Top K Frequent Elements
    1. Top K Frequent Words
  • 252 Meeting Rooms (Premium)
  • 253 Meeting Rooms II (Premium)
  • 370 Range Addition (Premium)
  • Merge k sorted arrays
  • 23 Merge k Sorted Lists
  • 358 Rearrange String k Distance Apart (Premium)
  • *857 Minimum Cost to Hire K Workers

TreeSet [6]

  • 217 Contains Duplicate
  • 219 Contains Duplicate II
  • *220 Contains Duplicate III
  • *363 Max Sum of Rectangle No Larger Than K
  • Maximum Sum Of Subarray Close To K
  • 683 K Empty Slots (Premium)

Stream (deque/caching/heap/treeset) [6]

  • 239 Sliding Window Maximum
  • 295 Find Median from Data Stream
  • 346 Moving Average from Data Stream (Premium)
  • *352 Data Stream as Disjoint Intervals
  • *382 Linked List Random Node

    *398. Random Pick Index

  • *384 Shuffle an Array

Sort [6]

  • *148 Sort List (Merge Sort)
  • Quick sort
  • *215 Kth Largest Element in an Array (Quick Sort)
  • 75 Sort Colors
  • *164 Maximum Gap
  • 49 Group Anagrams

tracking index using an array [4]

  • 263 Ugly Number
  • *264 Ugly Number II
  • *313 Super Ugly Number
  • *373 Find K Pairs with Smallest Sums

Rotate [2]

  • *189 Rotate Array
  • 151 Reverse Words in a String

    Finding a Number [3]

  • 268 Missing Number
  • 287 Find the Duplicate Number
  • *41 First Missing Positive

    using index to add elements to a list [1]

  • *406 Queue Reconstruction by Height

Iterate within a boundary if the boundary is fixed [2]

  • *401 Binary Watch
  • 681 Next Closest Time (Premium)

Matrix [26]

sorted matrix [3]

  • 74 Search a 2D Matrix
  • 240 Search a 2D Matrix II
  • *378 Kth Smallest Element in a Sorted Matrix

queue [1]

  • 353 Design Snake Game (Premium)

union-find (disjoint set) [3]

  • 305 Number of Islands II (Premium)
  • 323 Number of Connected Components in an Undirected Graph (Premium)
  • *947 Most Stones Removed with Same Row or Column

DFS [8]

  • *329 Longest Increasing Path in a Matrix
  • 79 Word Search
  • *212 Word Search II
  • 200 Number of Islands
  • Find a Path in a Matrix
  • *37 Sudoku Solver
  • 36 Valid Sudoku
  • 286 Walls and Gates (Premium)

BFS [1]

  • *130 Surrounded Regions

Others [9]

  • 73 Set Matrix Zeroes
  • 54 Spiral Matrix
  • 59 Spiral Matrix II
  • 48 Rotate Image
  • *304 Range Sum Query 2D - Immutable
  • 317 Shortest Distance from All Buildings (Premium)
  • 296 Best Meeting Point (Premium)
  • *289 Game of Life
  • 348 Design Tic-Tac-Toe (Premium)

matrix multiplication [1]

  • 311 Sparse Matrix Multiplication (Premium)

Linked List [22]

  • 2 Add Two Numbers
  • 143 Reorder List
  • 141 Linked List Cycle
  • 138 Copy List with Random Pointer
  • 21 Merge Two Sorted Lists
  • 328 Odd Even Linked List
  • 83 Remove Duplicates from Sorted List
  • 82 Remove Duplicates from Sorted List II
  • 86 Partition List
  • 160 Intersection of Two Linked Lists
  • 203 Remove Linked List Elements
  • 24 Swap Nodes in Pairs
  • 206 Reverse Linked List
  • 92 Reverse Linked List II
  • 19 Remove Nth Node From End of List
  • 234 Palindrome Linked List
  • 237 Delete Node in a Linked List
  • 25 Reverse Nodes in k-Group
  • *148 Sort List
  • Reverse Double Linked List
  • Print Linked List in Reversed Order
  • 369 Plus One Linked List (Premium)

Tree [47]

travel [6]

  • 94 Binary Tree Inorder Traversal
  • 144 Binary Tree Preorder Traversal
  • 145 Binary Tree Postorder Traversal
  • 102 Binary Tree Level Order Traversal
  • 107 Binary Tree Level Order Traversal II
  • 314 Binary Tree Vertical Order Traversal
    • *987 Vertical Order Traversal of a Binary Tree

dfs/bfs [37]

  • 226 Invert Binary Tree
  • 230 Kth Smallest Element in a BST
  • 298 Binary Tree Longest Consecutive Sequence (Premium)
  • 98 Validate Binary Search Tree
  • 114 Flatten Binary Tree to Linked List
  • 112 Path Sum
  • 113 Path Sum II
    • 437 Path Sum III
  • 106 Construct Binary Tree from Inorder and Postorder Traversal
  • 105 Construct Binary Tree from Preorder and Inorder Traversal
  • 108 Convert Sorted Array to Binary Search Tree
  • 109 Convert Sorted List to Binary Search Tree
  • 111 Minimum Depth of Binary Tree
  • 124 Binary Tree Maximum Path Sum
  • 110 Balanced Binary Tree
  • 101 Symmetric Tree
  • 173 Binary Search Tree Iterator
  • 199 Binary Tree Right Side View
  • 235 Lowest Common Ancestor of a Binary Search Tree
  • 236 Lowest Common Ancestor of a Binary Tree
  • *1026. Maximum Difference Between Node and Ancestor
  • 508 Most Frequent Subtree Sum
  • *331 Verify Preorder Serialization of a Binary Tree
  • 116 Populating Next Right Pointers in Each Node
  • 117 Populating Next Right Pointers in Each Node II
  • 96 Unique Binary Search Trees
  • 95 Unique Binary Search Trees II
  • 129 Sum Root to Leaf Numbers
  • 222 Count Complete Tree Nodes
  • 270 Closest Binary Search Tree Value (Premium)
  • 257 Binary Tree Paths
  • 104 Maximum Depth of Binary Tree
  • *99 Recover Binary Search Tree
  • 100 Same Tree
  • *297 Serialize and Deserialize Binary Tree
  • 285 Inorder Successor in BST (Premium)
  • 510 Inorder Successor in BST II (Premium)
  • 366 Find Leaves of Binary Tree (Premium)
  • 333 Largest BST Subtree (Premium)
  • 426 Convert Binary Search Tree to Sorted Doubly Linked List (Premium)

Trie [2]

  • 208 Implement Trie (Prefix Tree)
  • *211 Design Add and Search Words Data Structure

Segment Tree & Binary Index Tree [2]

  • *307 Range Sum Query - Mutable
  • *218 The Skyline Problem

Stack [18]

Stack and Queue data structure implementation (get familiar with stack and queue) [4]

  • 225 Implement Stack using Queues
  • 232 Implement Queue using Stacks
  • Implement a Stack Using an Array
  • Implement a Queue using an Array

Stack [5]

  • 150 Evaluate Reverse Polish Notation
  • 20 Valid Parentheses
  • *32 Longest Valid Parentheses
  • 155 Min Stack
  • *769 Max Chunks To Make Sorted

Stack–Largest Rectangle [2]

  • *84 Largest Rectangle in Histogram
  • *85 Maximal Rectangle

Stack–Nested Object [7]

  • *385 Mini Parser
  • 341 Flatten Nested List Iterator
  • 339 Nested List Weight Sum (Premium)
  • 364 Nested List Weight Sum II (Premium)
  • *388 Longest Absolute File Path
  • *394 Decode String
  • Evaluate Math Expression

    DFS [28]

  • 698 Partition to K Equal Sum Subsets
  • 46 Permutations
  • 47 Permutations II
  • *60 Permutation Sequence

    *31 Next Permutation

  • *996 Number of Squareful Arrays
  • *22 Generate Parentheses
  • 39 Combination Sum
  • 40 Combination Sum II
  • 216 Combination Sum III
  • *377 Combination Sum IV
  • *44 Wildcard Matching
  • *10 Regular Expression Matching
  • *809 Expressive Words
  • Get Target Using Number List And Arithmetic Operations
  • 293 Flip Game (Premium)
  • 294 Flip Game II (Premium)
  • 290 Word Pattern
  • 291 Word Pattern II (Premium)
  • 87 Scramble String
  • *301 Remove Invalid Parentheses
  • *214 Shortest Palindrome
  • *386 Lexicographical Numbers
  • 77 Combinations
  • 17 Letter Combinations of a Phone Number
  • *93 Restore IP Addresses
  • 254 Factor Combinations (Premium)
  • 78 Subsets
  • 90 Subsets II

Dynamic Programming [31]

  • 322 Coin Change
  • *131 Palindrome Partitioning
  • *132 Palindrome Partitioning II
  • 198 House Robber
  • 213 House Robber II
  • 337 House Robber III
  • 55 Jump Game
  • 45 Jump Game II
  • 121 Best Time to Buy and Sell Stock
  • 122 Best Time to Buy and Sell Stock II
    1. Best Time to Buy and Sell Stock with Cooldown
    2. Best Time to Buy and Sell Stock with Transaction Fee
  • *123 Best Time to Buy and Sell Stock III
  • *188 Best Time to Buy and Sell Stock IV
  • *174 Dungeon Game
  • *91 Decode Ways
  • *279 Perfect Squares
  • *139 Word Break
  • *140 Word Break II
  • 727 Minimum Window Subsequence (Premium)
  • *221 Maximal Square
  • 64 Minimum Path Sum
  • 62 Unique Paths
  • *63 Unique Paths II
  • 256 Paint House (Premium)
  • 265 Paint House II (Premium)
  • 53 Maximum Subarray
  • 152 Maximum Product Subarray

DP–2D

  • 72 Edit Distance
    1. Delete Operation for Two Strings
    2. Minimum ASCII Delete Sum for Two Strings
  • 115 Distinct Subsequences Total
  • 5 Longest Palindromic Substring
  • 1143 Longest Common Subsequence
    1. Longest Palindromic Subsequence
  • Longest Common Substring

Data Structure Design [6]

  • *146 LRU Cache
  • 380 Insert Delete GetRandom O(1)
  • *381 Insert Delete GetRandom O(1) - Duplicates allowed
  • Insert Delete GetMostFrequent O(1)
  • 379 Design Phone Directory (Premium)
  • *355 Design Twitter

Bit Manipulation [12]

  • 136 Single Number
  • *137 Single Number II
    1. Single Number III
  • Maximum Binary Gap
  • 191 Number of 1 Bits
  • 190 Reverse Bits
  • *187 Repeated DNA Sequences
  • 201 Bitwise AND of Numbers Range
  • *371 Sum of Two Integers
  • 338 Counting Bits
  • *318 Maximum Product of Word Lengths
  • *89 Gray Code
  • *393 UTF-8 Validation

Graph [6]

topological sort

  • *207 Course Schedule
  • *210 Course Schedule II
  • *310 Minimum Height Trees

BFS/DFS

    1. Graph Valid Tree (Premium)
  • 133 Clone Graph
  • *332 Reconstruct Itinerary

Math/Numbers

power

  • 50 Pow(x,n)
  • 231 Power of Two
  • 326 Power of Three
  • 342 Power of Four
  • *372 Super Pow

/%

  • 7 Reverse Integer

  • 9 Palindrome Number

  • *400 Nth Digit

  • *166 Fraction to Recurring Decimal

  • 171 Excel Sheet Column Number

  • 168 Excel Sheet Column Title

  • *172 Factorial Trailing Zeroes

  • 202 Happy Number

  • 204 Count Primes

  • *66 Plus One

  • 29 Divide Two Integers

  • 43 Multiply Strings

  • *149 Max Points on a Line

  • *343 Integer Break

  • 258 Add Digits

  • *368 Largest Divisible Subset

  • 357 Count Numbers with Unique Digits

  • *787 Rotated Digits

  • *402 Remove K Digits

Other

  • *179 Largest Number
  • 120 Triangle
  • *8 String to Integer
  • 28 Implement strStr()
  • 6 ZigZag Conversion
  • 67 Add Binary
  • 58 Length of Last Word
  • 299 Bulls and Cows
  • *71 Simplify Path
  • *165 Compare Version Numbers
  • 118 Pascal’s Triangle
  • 119 Pascal’s Triangle II
  • 38 Count and Say
  • *224 Basic Calculator
  • *227 Basic Calculator II
  • *223 Rectangle Area
  • 162 Find Peak Element
  • *273 Integer to English Words
  • 68 Text Justification
  • 134 Gas Station
  • *335 Self Crossing
  • *330 Patching Array
  • 292 Nim Game
  • 319 Bulb Switcher
  • 276 Paint Fence (Premium)
  • 339 Nested List Weight Sum (Premium)