Skip to content

This list contains solutions to most questions I have solved on LeetCode

Notifications You must be signed in to change notification settings

trung-hn/leetcode-solutions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 

Repository files navigation

About

  • This list was initially created for personal use
  • Headers and footers of source code are generated from extension LeetCode in VSCode

My LEETCODE profile

Trung Hoang

Tips to Improve your Skills

  • Solve problems by topic: when you first started, it is important to understand different topics quickly and solving 10-20 problems per topic is a good way to grasp the concept.
  • If you are using Python and are interested in writing Pythonic code, I created a repo for Python tips and tricks
  • Always aim to get a better solution by reading the discussion after you successfully solves a problem. Leetcode's community is amazing, you will learn of lot of useful tips and tricks to make your code cleaner and faster from the discussion posts.
  • Leetcode has a "Taking Note" system where you can take notes of things you learn for each problem. Make good use of it.
  • Leetcode's category of difficulty (Easy, Medium, Hard) is not always correct. My rule of thumb is looking at the acceptance rate. >55% means Easy and <35% means Hard
  • What is correct is the amount of likes and dislikes of a problem. Problems with more dislikes than likes are usually not worth solving. Try a different one.
  • When you are stuck, there are a few things you can do to give yourself hints:
    1. Look at the tag for the problem and see what kind of algorithm or data structure is needed for solving
    2. Look at the hints provided by Leetcode
    3. Quickly look at the discussion title to see what the expected complexity is or the name of the algorithm.
    4. Estimate the Time Complexity of the problem based on the input constraints (see next tip)
  • You can estimate the Time complexity based on the input constraints as follows:
input size estimated time complexity
N <= 10 O(N!)
N <= 20 O(2^N)
N <= 10^2 O(N^3)
N <= 10^3 O(N^2)
N <= 10^4 O(NlogN)
N <= 10^6 O(N)
N > 10^6 O(1) or O(logN)

Solutions list (~600 Problems)

# Title Level Time Space Tags Note Premium 🔒
1 Two Sum Easy O(N) O(N)
7 Reverse Integer Easy O(log x) O(1) Tricky
11 Container With Most Water Medium O(N) O(1) Array, Two Pointers, Greedy
12 Integer to Roman Medium O(N) O(N) Math, String
13 Roman to Integer Easy O(N) O(1) Math, String
15 3Sum Medium O(N^2) O(N^2) Array, Two Pointers
17 Letter Combinations of a Phone Number Medium O(2^2) O(2^N) String, Backtracking, DFS, Recursion
19 Remove Nth Node From End of List Medium O(N) O(1) Linked List, Two Pointers
20 Valid Parentheses Easy O(N) O(N) String, Stack
21 Merge Two Sorted Lists Easy O(N) O(1) Linked List
22 Generate Parentheses Medium Complex Complex String, Backtracking
24 Swap Nodes in Pairs Medium O(N) O(N) Linked List
25 Reverse Nodes in k-Group Hard O(N) O(1) Linked List, Recursion
30 Substring with Concatenation of All Words Hard O(NK) O(K) Array, Backtracking
32 Longest Valid Parentheses Hard O(N) O(N) String, Dynamic Programming
34 Find First and Last Position of Element in Sorted Array Medium O(logN) O(1) Array, Binary Search Template for Binary Search
39 Combination Sum Medium O(N^2) O(N) Array, Backtracking
42 Trapping Rain Water Hard O(N) O(N) Array, Two Pointers, Dynamic Programming, Stack
45 Jump Game II Medium O(N) O(1) Array, Greedy
46 Permutations Medium O(N!) O(N!) Backtracking
47 Permutations II Medium O(N!) O(N!) Backtracking
48 Rotate Image Medium O(N*M) O(1) Array
51 N-Queens Hard O(N!) O(N^2) Backtracking
51 N-Queens II Hard O(N!) O(N^2) Backtracking
53 Maximum Subarray Easy O(N) O(1)
57 Insert Interval Hard O(N) O(N) Array, Sort, Greedy
59 Spiral Matrix II Medium O(N^2) O(N^2) Array
61 Rotate List Medium O(N) O(1) Linked List, Two Pointers
63 Unique Paths II Medium O(M*N) O(M) Array, Dynamic Programming
71 Simplify Path Medium O(N) O(N) String, Stack
72 Edit Distance Hard O(N*M) O(N) String, Dynamic Programming
74 Search a 2D Matrix Medium O(logN + logM) O(1) Binary Search
76 Minimum Window Substring Hard O(S+T) O(S+T) Hash Table, Two Pointers, String, Sliding Window
78 Subsets Medium O(N*2^N) O(N*2^N) Backtracking, Bit Manipulation
80 Remove Duplicates from Sorted Array II Medium O(N) O(1) Array, Two Pointers
82 Remove Duplicates from Sorted List II Medium O(N) O(1) Linked List
84 Largest Rectangle in Histogram Hard O(N) O(N) Array, Stack, Monotonic Stack
85 Maximal Rectangle Hard O(R*C*C) O(C) Array, Dynamic Programming, Stack, Matrix, Monotonic Stack
89 Gray Code Medium O(2^N) O(2^N) Math, Backtracking, Bit Manipulation
91 Decode Ways Medium O(N) O(N) String, Dynamic Programming
92 Reverse Linked List II Medium O(N) O(1) Linked List
94 Binary Tree Inorder Traversal Easy O(N) O(N) Stack, Tree, DFS, Binary Tree
99 Recover Binary Search Tree Hard O(N) O(N) Tree, DFS
100 Same Tree Easy O(N) O(H) Tree, Pythonic
102 Binary Tree Level Order Traversal Medium O(N) O(N) Tree, BFS
104 Maximum Depth of Binary Tree Easy O(N) O(N) Tree, BFS, DFS
105 Construct Binary Tree from Preorder and Inorder Traversal Medium O(N) O(N) Array, Tree, DFS
106 Construct Binary Tree from Inorder and Postorder Traversal Medium O(N) O(N) Array, Hash Table, Divide and Conquer, Tree, Binary Tree
107 Binary Tree Level Order Traversal II Easy O(N) O(N) Tree, BFS
111 Minimum Depth of Binary Tree Easy O(N) O(H) Tree, DFS, BFS
114 Flatten Binary Tree to Linked List Medium O(N) O(1) Tree, DFS
115 Distinct Subsequences Medium O(N) O(1) String, Dynamic Programming
116 Populating Next Right Pointers in Each Node Medium O(N) O(N) Tree, DFS, BFS
119 Pascal's Triangle II Easy O(k^2) O(k) Array
121 Best Time to Buy and Sell Stock Easy O(N) O(1) Dynamic Programming
122 Best Time to Buy and Sell Stock II Easy O(N) O(1) Array, Greedy
125 Valid Palindrome Easy O(1) O(1) String
127 Word Ladder Hard O(M^2*N) O(M^2*N) BFS
128 Longest Consecutive Sequence Medium O(N) O(N) Array
130 Surrounded Regions Medium O(N*M) O(N*M) Array, BFS, DFS, Union Find, Matrix
131 Palindrome Partitioning Medium O(N*2^N) O(N*N) String, Dynamic Programming, Backtracking
133 Clone Graph Medium O(N+M) O(N) DFS, BFS, Graph
134 Gas Station Medium O(N) O(N) Dynamic Programming, Greedy
135 Candy Hard O(N) O(N) Greedy
138 Copy List with Random Pointer Medium O(N) O(N) Hash Table, Linked List
139 Word Break Medium O(N^2) O(N) Dynamic Programming
141 Linked List Cycle Easy O(N) O(1) Linked List, Two Pointers
142 Linked List Cycle II Medium O(N) O(1) Linked List, Two Pointers
143 Reorder List Medium O(N) O(1) Linked List
144 Binary Tree Preorder Traversal Easy O(N) O(N) Stack, Tree, DFS, Binary Tree
145 Binary Tree Postorder Traversal Easy O(N) O(N) Stack, Tree, DFS, Binary Tree
146 LRU Cache Medium Design Design Hash Table, Linked List, Design, Doubly-Linked List
147 Insertion Sort List Medium O(N^2) O(1) Sort, Linked List
151 Evaluate Reverse Polish Notation Medium O(N) O(N) Stack
151 Reverse Words in a String Easy O(N) O(N) String
152 Maximum Product Subarray Medium O(N) O(N) Dynamic Programming, Array
153 Find Minimum in Rotated Sorted Array Medium O(logN) O(1) Binary Search
154 Find Minimum in Rotated Sorted Array II Hard O(logN) O(1) Binary Search
159 Longest Substring with At Most Two Distinct Characters Medium O(N) O(1) Premium, Hash Table, Two Pointers, String, Sliding Window
165 Compare Version Numbers Medium O(N) O(1) String
168 Excel Sheet Column Title Medium O(logN) O(logN) Math Math Tricks
171 Excel Sheet Column Number Easy O(N) O(1) String
175 Combine Two Tables Easy N/A N/A Database
178 Rank Scores Medium N/A N/A Database
179 Largest Number Medium O(NlogN) O(1) Sort
182 Duplicate Emails Easy N/A N/A Database
183 Customers Who Never Order Easy N/A N/A Database
187 Repeated DNA Sequences Medium O(N-L) O(N-L) Hash Table, Bit Manipulation
190 Reverse Bits Easy O(1) O(1) Bit Manipulation
198 House Robber Medium O(N) O(1) Dynamic Programming
200 Number of Islands Medium O(R*C) O(R*C) Array, BFS, DFS, Union Find, Matrix
203 Count Primes Easy O(N) O(1) Linked List, Recursion
204 Count Primes Medium O(loglogN) O(N) Hash Table, Math
207 Course Schedule Medium O(N + E) O(N + E) BFS, DFS, Graph, Topological Sort
208 Implement Trie (Prefix Tree) Medium Varying Varying Design, Trie
209 Minimum Size Subarray Sum Medium O(N) O(1) Array, Two Pointers, Binary Search
211 Add and Search Word - Data structure design Medium O(M) O(1) Trie, Design
213 House Robber II Medium O(N) O(1) Dynamic Programming
215 Kth Largest Element in an Array Medium O(NlogK) O(K) Heap
216 Combination Sum III Medium O(N^2) O(N^2) Array, Backtracking
218 The Skyline Problem Hard O(NlogN) O(N) Divide and Conquer, Heap, Binary Indexed Tree, Segment Tree, Line Sweep
220 Contains Duplicate III Medium O(N) O(N) Sort, Ordered Map
221 Maximal Square Medium O(N * M) O(1) Array, Dynamic Programming
222 Count Complete Tree Nodes Medium O(logN * logN) O(1) Binary Search, Tree
227 Basic Calculator II Medium O(N) O(N) String, Stack
228 Summary Ranges Easy O(N) O(1) Array
229 Majority Element II Medium O(N) O(1) Array
230 Kth Smallest Element in a BST Medium O(H + k) O(H + k) Tree, DFS Use general formula for tree traversal
231 Power of Two Easy O(1) O(1) Bit Manipulation Important technique in bit manipulation
234 Palindrome Linked List Easy O(N) O(1) Linked List, Two Pointers
239 Sliding Window Maximum Hard O(N) O(N) Monotonic Dequeue, Sliding Window, Heap
252 Meeting Rooms Easy O(NlogN) O(1) Premium, Sort 🔒
253 Meeting Rooms II Medium O(NlogN) O(N) Premium, Heap, Greedy, Sort 🔒
264 Ugly Number II Medium O(1) O(1) Heap, Dynamic Programming
268 Missing Number Easy O(N) O(1) Array, Math, Bit Manipulation
270 Closest Binary Search Tree Value Easy O(H) O(1) Premium, Binary Search, Tree 🔒
273 Integer to English Words Medium O(logN) O(1) Math, String
274 H-Index Medium O(NlogN) O(N) Hash Table, Sort There is a better solution
279 Perfect Squares Medium O(NlogN) O(N) Math, Dynamic Programming, BFS
283 Move Zeroes Easy O(N) O(1) Array, Two Pointers
284 Peeking Iterator Medium O(NlogN) O(N) Design
289 Game of Life Medium O(M*N) O(1) Array
290 Word Pattern Easy O(N) O(N) Hash Table
295 Find Median from Data Stream Hard O(logN) O(N) Design, Hard, Heap
296 Best Meeting Point Hard O(M*N) O(M+N) Premium, Math 🔒
297 Serialize and Deserialize Binary Tree Hard O(N) O(N) Tree, Design
299 Bulls and Cows Easy O(N) O(N) Hash Table
300 Longest Increasing Subsequence Medium O(NlogN) O(N) Binary Search, Dynamic Programming, Popular Algorithm
304 Range Sum Query 2D - Immutable Medium O(1) O(R*C) Dynamic Programming Matrix Range Sum Trick
307 Range Sum Query - Mutable Medium O(logN) O(logN) Array, Design, Binary Indexed Tree, Segment Tree
310 Minimum Height Trees Medium O(V) O(V) BFS, Graph
312 Burst Balloons Hard O(N^3) O(N^2) Array, Dynamic Programming
315 Count of Smaller Numbers After Self Hard O(NlogN) O(N) Array, Binary Search, Divide and Conquer, Binary Indexed Tree, Segment Tree, Merge Sort, Ordered Set
316 Remove Duplicate Letters Hard O(N) O(1) Greedy, Tricky, Stack
317 Shortest Distance from All Buildings Hard O(N*M) O(N*M) BFS, Premium 🔒
319 Bulb Switcher Medium O(1) O(1) Math, Tricky
320 Generalized Abbreviation Medium O(N*2^N) O(N) Premium, Backtracking 🔒
322 Coin Change Medium O(A*N) O(A) Dynamic Programming
328 Odd Even Linked List Medium O(N) O(1) Linked List
329 Longest Increasing Path in a Matrix Hard O(R*C) O(R*C) DFS, Topology Sort, Memoization
331 Verify Preorder Serialization of a Binary Tree Medium O(N) O(N) String, Stack, Tree, Binary Tree
334 Increasing Triplet Subsequence Medium O(N) O(1) Array
337 House Robber III Medium O(N) O(N) Dynamic Programming, Tree, DFS
338 Counting Bits Medium O(N) O(N) Dynamic Programming, Bit Manipulation
342 Power of Four Easy O(1) O(1) Math, Bit Manipulation
344 Integer Break Medium O(N) O(1) Math, Dynamic Programming
346 Moving Average from Data Stream Easy O(1) O(N) Premium, Design 🔒
347 Top K Frequent Elements Medium O(N) O(N) Hash Table, Heap
348 Design Tic-Tac-Toe Medium O(1) O(N^2) Premium, Design 🔒
351 Android Unlock Patterns Medium O(N!) O(N) Dynamic Programming, Backtracking, Premium 🔒
354 Russian Doll Envelopes Hard O(NlogN) O(N) Binary Search, Dynamic Programming
357 Count Numbers with Unique Digits Medium O(1) O(1) Math, Dynamic Programming, Backtracking
361 Bomb Enemy Medium O(N*M) O(N*M) Premium, Dynamic Programming 🔒
362 Design Hit Counter Medium O(1) O(N) Design, Premium 🔒
363 Max Sum of Rectangle No Larger Than K Hard O(R*R*C*logC) O(R*C) Array, Binary Search, Dynamic Programming, Matrix, Ordered Set
367 Valid Perfect Square Easy O(logN) O(1) Math, Binary Search
376 Wiggle Subsequence Medium O(N) O(1) Greedy, Dynamic Programming
377 Combination Sum IV Medium O(T*N) O(T) Dynamic Programming
378 Kth Smallest Element in a Sorted Matrix Medium O(N^2logK) O(K) Heap, Binary Search
380 Insert Delete GetRandom Medium O(1) O(N) Array, Hash Table, Design
384 Shuffle an Array Medium O(N) O(N)
387 First Unique Character in a String Easy O(N) O(N)
389 Find the Difference Medium O(N) O(1) Hash Table, Bit Manipulation
394 Decode String Medium O(maxK*N) O(N) Stack, DFS
395 Longest Substring with At Least K Repeating Characters Medium O(NlogN) O(N) Divide and Conquer, Recursion, Sliding Window
399 Evaluate Division Medium O(N*M) O(N) Union Find, Graph
402 Remove K Digits Medium O(N) O(N) Greedy
404 Sum of Left Leaves Easy O(N) O(H) Tree
406 Queue Reconstruction by Height Medium O(N^2) O(N) Greedy Clever solution
413 Arithmetic Slices Medium O(N) O(1) Math, Dynamic Programming
416 Partition Equal Subset Sum Medium O(M*N) O(M) Dynamic Programming
417 Pacific Atlantic Water Flow Medium O(R*C) O(R*C) DFS, BFS
419 Battleships in a Board Medium O(N*N) O(1) Array, DFS
423 Reconstruct Original Digits from English Medium O(N) O(N) Math
425 Word Squares Hard Complex Complex Back Tracking, Trie, Premium 🔒
428 Serialize and Deserialize N-ary Tree Hard O(N) O(H) Tree, Premium 🔒
431 Encode N-ary Tree to Binary Tree Hard O(N) O(H) Tree, Premium 🔒
433 Minimum Genetic Mutation Medium O(E+V) O(E+V) Hash Table, String, BFS
435 Non-overlapping Intervals Medium O(NlogN) O(1) Greedy Tricky, Hard
436 Find Right Interval Medium O(NlogN) O(N) Binary Search Bad Description
437 Path Sum III Medium O(N) O(N) Tree Tricky, Hard
438 Find All Anagrams in a String Medium O(N_s + N_p) O(1) Hash Table
441 Arranging Coins Easy O(1) O(1) Math, Binary Search
442 Find All Duplicates in an Array Medium O(N) O(1) Array
445 Add Two Numbers II Medium O(N) O(N) Linked List
449 Serialize and Deserialize BST Medium O(N) O(N) Tree
450 Delete Node in a BST Medium O(H) O(H) Binary Search Tree
451 Sort Characters By Frequency Medium O(N) O(N) Hash Table, Sorting, Pythonic
452 Minimum Number of Arrows to Burst Balloons Medium O(NlogN) O(1) Sort, Greedy
454 4Sum II Medium O(N^2) O(N^2) Array
456 132 Pattern Medium O(N) O(N) Stack
458 Poor Pigs Hard O(1) O(1) Math
462 Minimum Moves to Equal Array Elements II Median O(NlogN) O(N) Math
463 Island Perimeter Easy O(N*M) O(1) Greedy
470 Implement Rand10() Using Rand7() Medium O(1) O(1) Math
473 Matchsticks to Square Medium O(4^N) O(4^N) DFS, Dynamic Programming
474 Ones and Zeroes Medium O(K*M*N) O(K*M*N) Dynamic Programming
476 Number Complement Easy O(N) O(1) Bit Manipulation
478 Generate Random Point in a Circle Medium O(1) O(1) Math, Random, Rejection Sampling
491 Increasing Subsequences Medium O(Combination) O(Combination) DFS
494 Target Sum Medium O(N*T) O(T) Dynamic Programming, DFS Template for DP
495 Teemo Attacking Medium O(N) O(1) Array
497 Random Point in Non-overlapping Rectangles Medium O(logN) O(N) Design, Binary Search
498 Diagonal Traverse Medium O(R*C) O(R*C) Array
502 IPO Hard O(NlogN) O(N) Array, Greedy, Sorting, Heap
506 Relative Ranks Medium O(NlogN) O(N) Array, Sorting, Heap (Priority Queue)
510 Inorder Successor in BST II Medium O(H) O(1) Tree, Premium 🔒
514 Freedom Trail Hard O(N*M) O(N*M) String, Dynamic Programming, Depth-First Search, Breadth-First Search 🔒
520 Detect Capital Easy O(N) O(1)
524 Longest Word in Dictionary through Deleting Medium Complex Complex Two Pointers, Sort
525 Contiguous Array Medium O(N) O(N) Hash Table Very good problem
528 Random Pick with Weight Medium O(N), O(logN) O(N), O(1) Binary Search, Random Pythonic
532 K-diff Pairs in an Array Medium O(N) O(N) Array, Two Pointers
538 Convert BST to Greater Tree Medium O(N) O(H) Tree, BFS, DFS, Recursion
540 Single Element in a Sorted Array Medium O(logN) O(1) Binary Search
542 01 Matrix Medium O(R*C) O(R*C) BFS, DFS
554 Brick Wall Medium O(N) O(N) Hash Table
563 Binary Tree Tilt Easy O(N) O(H) Tree, DFS, Recursion
567 Permutation in String Medium O(S1 + S2) O(1) String, Two Pointers, Sliding Window
573 Squirrel Simulation Medium O(N) O(1) Premium, Math 🔒
576 Out of Boundary Paths Medium O(N*m*n) O(N*m*n) Dynamic Programming
581 Shortest Unsorted Continuous Subarray Medium O(N) O(1) Array
583 Delete Operation for Two Strings Medium O(N^2) O(N) Dynamic Programming, String
589 N-ary Tree Preorder Traversal Easy O(N) O(N) Tree
593 Valid Square Medium O(1) O(1) Math
605 Can Place Flowers Easy O(N) O(1) Array, Greedy
611 Valid Triangle Number Medium O(N^2) O(1) Array, Two Pointers, Binary Search, Greedy, Sorting
621 Task Scheduler Medium O(N) O(1) Array, Hash Table, Greedy, Sorting, Heap (Priority Queue), Counting Greedy
622 Design Circular Queue Medium O(1) O(1) Design, Queue
623 Add One Row to Tree Medium O(N) O(N) Tree
624 Maximum Distance in Arrays Easy O(N) O(1) Hash Table, Array, Premium 🔒
629 K Inverse Pairs Array Hard O(N * K) O(K) Dynamic Programming
633 Sum of Square Numbers Medium O(logN) O(logN) Math, Two Pointers, Binary Search
636 Exclusive Time of Functions Medium O(N) O(N) Array, Stack
639 Decode Ways II Hard O(N) O(N) String, Dynamic Programming
646 Maximum Length of Pair Chain Medium O(NlogN) O(N) Greedy, Dynamic Programming
655 Print Binary Tree Medium O(N) O(H) Tree
658 Find K Closest Elements Medium O(logN+K) O(K) Tree
659 Split Array into Consecutive Subsequences Medium O(N) O(1) Greedy
662 Maximum Width of Binary Tree Medium O(N) O(N) Tree
665 Non-decreasing Array Medium O(N) O(1) Array
667 Beautiful Arrangement II Medium O(N) O(N) Array
669 Trim a Binary Search Tree Medium O(N) O(N) Tree, Recursion
670 Maximum Swap Medium O(N) O(N) Array, Math
673 Number of Longest Increasing Subsequence Medium O(N^2) O(N) Dynamic Programming
677 Map Sum Pairs Medium O(K) O(K) Trie
684 Redundant Connection Medium O(NlogN) O(N) DFS, BFS, Union Find, Graph
696 Count Binary Substrings Medium O(N) O(1) String
697 Degree of an Array Easy O(N) O(N) Array, Hash Table
700 Search in a Binary Search Tree Easy O(H) O(1) Tree
701 Insert into a Binary Search Tree Medium O(H) O(1) Tree
702 Search in a Sorted Array of Unknown Size Medium O(logN) O(1) Binary Search, Premium 🔒
705 Design HashSet Easy Varying Varying Design HashSet
708 Insert into a Sorted Circular Linked List Medium O(N) O(1) Linked List, Premium 🔒
713 Subarray Product Less Than K Medium O(N) O(1) Array, Two Pointers
714 Best Time to Buy and Sell Stock with Transaction Fee Medium O(N) O(1) Array, Dynamic Programming, Greedy
717 1-bit and 2-bit Characters Easy O(N) O(1) Array, Greedy
721 Accounts Merge Medium Complex Complex Union-Find, DFS Template for Union-Find
724 Find Pivot Index Easy O(N) O(1) Array, Prefix Sum
725 Split Linked List in Parts Medium O(N) O(N) Linked List
729 My Calendar I Medium O(NlogN) O(N) Tree
733 Flood Fill Easy O(N) O(N) DFS
734 Sentence Similarity Easy O(N) O(N) Premium, Hash Table 🔒
735 Asteroid Collision Medium O(N) O(N) Stack
737 Sentence Similarity II Medium O(NlogP + P) or O(NP) O(N) Premium, DFS, Union Find 🔒
738 Monotone Increasing Digits Medium O(logN) O(logN) Greedy
739 Daily Temperatures Medium O(N) O(N) Hash Table, Stack
740 Delete and Earn Medium O(N+M) O(N+M) Dynamic Programming
743 Network Delay Time Medium O(ElogE) O(N + E) Heap, BFS, DFS, Graph
746 Min Cost Climbing Stairs Easy O(N) O(1) Array, DP
752 Open the Lock Medium O(N^2*D^N) O(N^2*D^N) BFS
754 Reach a Number Medium O(logN) O(1) Math
763 Partition Labels Medium O(N) O(N) Greedy, Two Pointers
764 Largest Plus Sign Medium O(N^2) O(N^2) Array, Dynamic Programming
767 Reorganize String Medium O(NlogN) O(N) String, Heap, Greedy, Sort
768 Max Chunks To Make Sorted II Hard O(N) O(N) Array
769 Max Chunks To Make Sorted Medium O(N) O(1) Array
775 Global and Local Inversions Medium O(N) O(1) Array, Math
778 Swim in Rising Water Medium O(R*C*logN) O(R*C) Binary Search, Heap, DFS, Union Find
784 Letter Case Permutation Medium O(2^N) O(2^N) Backtracking, Bit Manipulation
785 Is Graph Bipartite? Medium O(E+V) O(E+V) BFS, DFS, Graph
786 K-th Smallest Prime Fraction Medium O(KlogK) O(K) Array, Two Pointers, Binary Search, Sorting, Heap (Priority Queue)
787 Cheapest Flights Within K Stops Medium Complex Complex Dijkstra's Algorithm, Graph Quite hard
789 Escape The Ghosts Medium O(N) O(1) Math
791 Custom Sort String Medium O(N) O(N) String
792 Number of Matching Subsequences Medium O(N + M * L) O(M) Array
794 Valid Tic-Tac-Toe State Medium O(1) O(1) Array, String
795 Number of Subarrays with Bounded Maximum Medium O(N) O(1) Array
797 All Paths From Source to Target Medium O(2^N * N) O(2^N * N) Backtracking, DFS
799 Champagne Tower Medium O(R^2) O(R^2) Dynamic Programming
802 Find Eventual Safe States Medium O(V+E) O(V+E) DFS, Graph
820 Short Encoding of Words Medium O(N*M) O(N*M) Trie
823 Binary Trees With Factors Medium O(N*N) O(N) Dynamic Programming
825 Friends Of Appropriate Ages Medium O(N) O(1) Array
827 Making A Large Island Hard O(N^2) O(N^2) Array, DFS, BFS, Union-Find, Matrix
830 Positions of Large Groups Easy O(N) O(1)
833 Find And Replace in String Medium O(N) O(N) Dynamic Programming
834 Sum of Distances in Tree Hard O(N) O(N) Dynamic Programming, Tree, DFS, Graph
835 Image Overlap Medium O(N^2) O(N)
838 Push Dominoes Medium O(N) O(N)
841 Keys and Rooms Medium O(N^2) O(N) DFS, Graph
845 Longest Mountain in Array Medium O(N) O(1) Two Pointers
846 Hand of Straights Medium O(MlogM+NW) O(N) Ordered Map
847 Shortest Path Visiting All Nodes Hard O(2^N * N^2) O(2^N * N) Dynamic Programming, Bit Manipulation, BFS, Graph Bitmask
848 Shifting Letters Medium O(N) O(N) Array, String
849 Maximize Distance to Closest Person Medium O(N) O(1) Array
851 Loud and Rich Medium O(N^2) O(N^2) DFS
853 Car Fleet Medium O(NlogN) O(N) Sort
857 Minimum Cost to Hire K Workers Medium O(NlogN) O(K) Array, Greedy, Sorting, Heap (Priority Queue)
858 Mirror Reflection Medium O(logN) O(1) Math
859 Buddy Strings Easy O(N) O(1) String
861 Score After Flipping Matrix Medium O(R*C) O(R*C) Array, Greedy, Bit Manipulation, Matrix
863 All Nodes Distance K in Binary Tree Medium O(N) O(N) Tree, BFS, DFS
865 Smallest Subtree with all the Deepest Nodes Medium O(N) O(N) Tree, BFS, DFS, Recursion
869 Reordered Power of 2 Medium O(logN) O(1) Math
870 Advantage Shuffle Medium O(NlogN) O(N) Array, Greedy
872 Leaf-Similar Trees Easy O(N) O(N) Tree, DFS, Binary Tree Iterator
873 Length of Longest Fibonacci Subsequence Medium O(N^2) O(N^2) Array, Dynamic Programming
875 Koko Eating Bananas Medium O(NlogM) O(1) Binary Search
880 Decoded String at Index Medium O(N) O(1) Stack Good problem
881 Boats to Save People Medium O(NlogN) O(N) Two Pointers, Greedy
886 Possible Bipartition Medium O(N + E) O(N + E) DFS Good problem
890 Find and Replace Pattern Medium O(N*K) O(N*K) String
892 Surface Area of 3D Shapes Easy O(N*N) O(1) Math, Geometry
895 Maximum Frequency Stack Medium O(1) O(N) Hash Table, Stack
901 Online Stock Span Medium O(1) O(N) Monotonic Stack
902 Numbers At Most N Given Digit Set Hard O(LogN) O(1) Math, Dynamic Programming
904 Fruit Into Baskets Medium O(N) O(1) Two Pointers
905 Sort Array By Parity Easy O(N) O(1) Array
906 Super Palindromes Hard Complex Complex Math
910 Smallest Range II Medium O(NlogN) O(N) Math, Greedy
911 Online Election Medium O(N + QlogN) O(N) Binary Search
915 Partition Array into Disjoint Intervals Medium O(N) O(N) Array
916 Word Subsets Medium O(A_t + B_t) O(L) String
918 Maximum Sum Circular Subarray Medium O(N) O(1) Array, Dynamic Programming
919 Complete Binary Tree Inserter Medium O(N) O(1) Tree
923 3Sum With Multiplicity Medium O(N^2) O(N) Two Pointers
926 Flip String to Monotone Increasing Medium O(N) O(N) Array
930 Binary Subarrays With Sum Medium O(N) O(N) Hash Table, Two Pointers
931 Minimum Falling Path Sum Medium O(R*C) O(C) Array, Dynamic Programming, Matrix
933 Number of Recent Calls Easy O(1) O(1) Queue
934 Shortest Bridge Medium O(E+V) O(E+V) BFS, DFS
935 Knight Dialer Medium O(N) O(1) Dynamic Programming
941 Valid Mountain Array Easy O(N) O(1) Array
946 Validate Stack Sequences Medium O(N) O(N) Stack
948 Bag of Tokens Medium O(NlogN) O(N) Greedy
953 Verifying an Alien Dictionary Easy O(A) O(1) Hash Table
954 Array of Doubled Pairs Medium O(NlogN) O(N) Array, Hash Table, Greedy, Sorting
957 Prison Cells After N Days Medium O(1) O(1) Hash Table
958 Check Completeness of a Binary Tree Medium O(N) O(N) Tree
962 Maximum Width Ramp Medium O(NlogN) O(N) Array
966 Vowel Spellchecker Medium O(N) O(N) Hash Table, String
967 Numbers With Same Consecutive Differences Medium O(N*2^N) O(2^N) DFS
968 Binary Tree Cameras Hard O(N) O(H) Greedy, Tree, Dynamic Programming, DFS New Technique
969 Pancake Sorting Medium O(N^2) O(N) Array
970 Powerful Integers Medium O(logx*logy) O(logx+logy) Hash Table, Math
971 Flip Binary Tree To Match Preorder Traversal Medium O(N) O(N) Tree, DFS
973 K Closest Points to Origin Medium O(N log(K)) O(K) Divide and Conquer, Heap, Sort
974 Subarray Sums Divisible by K Medium O(N) O(K) Array, Hash Table
976 Largest Perimeter Triangle Medium O(NlogN) O(N) Math, Sort
977 Squares of a Sorted Array Easy O(N) O(N) Array, Two Pointers
979 Distribute Coins in Binary Tree Medium O(N) O(H) Tree, DFS
980 Unique Paths III Medium O(2^N) O(N) Backtracking, DFS
983 Minimum Cost For Tickets Medium O(365) O(365) LRU Cache, Dynamic Programming
986 Interval List Intersections Medium O(N + M) O(1) Two Pointers
987 Vertical Order Traversal of a Binary Tree Medium O(NlogN) O(N) Hash Table, Tree
991 Broken Calculator Medium O(logN) O(1) Math, Greedy
992 Subarrays with K Different Integers Hard O(N) O(N) Hash Talble, Two Pointers, Sliding Window
993 Cousins in Binary Tree Easy O(N) O(H) Trees, Recursion
994 Rotting Oranges Medium O(N^2) O(N) Trees, Recursion
997 Find the Town Judge Medium O(N) O(N) Array, Hash Table, Graph
1003 Check If Word Is Valid After Substitutions Medium O(N) O(N) String, Stack
1004 Max Consecutive Ones III Medium O(N) O(1) Sliding Window, Two Pointers
1007 Minimum Domino Rotations For Equal Row Medium O(N) O(1) Array, Greedy
1009 Complement of Base 10 Integer Easy O(logN) O(1) Bit Manipulation
1010 Pairs of Songs With Total Durations Divisible by 60 Medium O(N) O(1) Array, Math
1011 Capacity To Ship Packages Within D Days Medium O(NlogN) O(1) Array, Binary Search
1014 Best Sightseeing Pair Medium O(N) O(1) Array
1015 Smallest Integer Divisible by K Medium O(K) O(K) Math
1022 Sum of Root To Leaf Binary Numbers Easy O(N) O(H) Tree
1023 Camelcase Matching Medium O(Q*N) O(Q) String, Trie
1024 Video Stitching Medium O(NlogN) O(1) Dynamic Programming
1026 Maximum Difference Between Node and Ancestor Medium O(N) O(H) Tree, DFS
1029 Two City Scheduling Easy O(NlogN) O(N) Greedy Good Problem
1032 Stream of Characters Hard O(M) O(M) Trie
1035 Uncrossed Lines Medium O(N^2) O(N) Array, Dynamic Programming
1042 Flower Planting With No Adjacent Medium O(V+E) O(V+E) Graph
1048 Longest String Chain Medium O(N*logN+N*C*C) O(N) Hash Table, Dynamic Programming
1049 Last Stone Weight II Medium O(N*S) O(N*S) Hash Table, Dynamic Programming Template for DP
1052 Grumpy Bookstore Owner Medium O(N) O(N) Sliding Window, Array
1053 Previous Permutation With One Swap Medium O(N) O(N) Array, Greedy
1054 Distant Barcodes Medium O(NlogN) O(N) Sort, Heap
1060 Missing Element in Sorted Array Medium O(logN) O(1) Binary Search, Premium 🔒
1061 Lexicographically Smallest Equivalent String Medium O(N) O(N) DFS, Union Find, Premium 🔒
1074 Number of Submatrices That Sum to Target Hard O(R*R*C) O(R*C) Array, Dynamic Programming, Sliding Window
1080 Insufficient Nodes in Root to Leaf Paths Medium O(N) O(N) DFS
1091 Shortest Path in Binary Matrix Medium O(N) O(N) BFS
1094 Car Pooling Medium O(N) O(1) Car Pooling
1109 Corporate Flight Bookings Medium O(N) O(N) Array, Math
1115 Print FooBar Alternately Medium N/A N/A Concurrency
1116 Print Zero Even Odd Medium N/A N/A Concurrency
1130 Minimum Cost Tree From Leaf Values Medium O(N) O(N) Dynamic Programming, Tree, Stack
1143 Longest Common Subsequence Medium O(M * N) O(M + N) String, Dynamic Programming
1155 Number of Dice Rolls With Target Sum Medium O(Complex) O(Complex) Graph, BFS
1162 As Far from Land as Possible Medium O(N*M) O(N*M) Graph, BFS
1171 Remove Zero Sum Consecutive Nodes from Linked List Medium O(N) O(N) Hash Table, Linked List
1178 Number of Valid Words for Each Puzzle Medium O(Complex) O(Complex) Array, Hash Table, String, Bit Manipulation, Trie
1192 Critical Connections in a Network Medium O(V+E) O(V+E) DFS, Tarjan New Algorithm
1208 Get Equal Substrings Within Budget Medium O(N) O(N) String, Binary Search, Sliding Window, Prefix Sum
1209 Remove All Adjacent Duplicates in String II Medium O(N) O(N) Stack
1217 Minimum Cost to Move Chips to The Same Position Easy O(N) O(1) Math, Greedy, Array
1218 Longest Arithmetic Subsequence of Given Difference Medium O(N) O(N) Hash Table, Math, Dynamic Programming
1219 Minimum CostPath with Maximum Gold Medium O(R*C+N*2^N) O(N) Backtracking
1220 Count Vowels Permutation Hard O(N) O(N) Dynamic Programming
1232 Check If It Is a Straight Line Easy O(N) O(1) Math, Pythonic, Geometry
1239 Maximum Length of a Concatenated String with Unique Characters Medium O(2^N) O(N) Backtracking, Bit Manipulation
1249 Minimum Remove to Make Valid Parentheses Medium O(N) O(N) Stack, String
1277 Count Square Submatrices with All Ones Medium O(N * M) O(1) Array, Dynamic Programming
1283 Find the Smallest Divisor Given a Threshold Medium O(NlogM) O(1) Binary Search
1288 Remove Covered Intervals Medium O(N) O(1) Greedy, Sort, Line Sweep
1289 Minimum Falling Path Sum II Hard O(N*M*M) O(1) Array, Dynamic Programming, Matrix
1290 Convert Binary Number in a Linked List to Integer Easy O(N) O(1) Linked List, Bit Manipulation
1291 Sequential Digits Medium O(N) O(N) Backtracking
1293 Shortest Path in a Grid with Obstacles Elimination Hard O(R*C) O(R*C) Array, BFS, Matrix
1298 Maximum Candies You Can Get from Boxes Medium O(B+K) O(B) BFS
1305 All Elements in Two Binary Search Trees Medium O(N) O(N) Sort, Tree
1306 All Elements inJump Game III Medium O(N) O(N) BFS, DFS, Recursion
1315 Sum of Nodes with Even-Valued Grandparent Medium O(N) O(N) Tree, DFS
1325 Delete Leaves With a Given Value Medium O(N) O(N) Tree, Depth-First Search, Binary Tree
1332 Remove Palindromic Subsequences Easy O(N) O(1) String
1337 The K Weakest Rows in a Matrix Easy O(MlogKlogN) O(K) Heap, Array, Binary Search
1339 Maximum Product of Splitted Binary Tree Medium O(N) O(N) Tree, DFS, Binary Tree
1344 Angle Between Hands of a Clock Medium O(1) O(1) Math
1345 Jump Game IV Hard O(N) O(N) BFS
1354 Construct Target Array With Multiple Sums Hard O(NlogN) O(N) Greedy, Heap Very Hard
1371 Find the Longest Substring Containing Vowels in Even Counts Medium O(N) O(N) String
1375 Bulb Switcher III Medium O(N) O(1) Array
1387 Sort Integers by The Power Value Medium O(NlogK) O(N) Sort, Graph
1395 Count Number of Teams Medium O(N^2) O(1) Array
1396 Design Underground System Medium O(N) O(N) Design
1405 Longest Happy String Medium O(N) O(N) Greedy, Dynamic Programming
1419 Minimum Number of Frogs Croaking Medium O(N) O(1) String
1423 Maximum Points You Can Obtain from Cards Medium O(N) O(1) Array, Dynamic Programming, Sliding Window
1424 Diagonal Traverse II Medium O(A) O(A) Array
1426 Counting Elements Easy O(N) O(N) Array, Premium 🔒
1427 Perform String Shifts Easy O(N + S) O(1) Premium 🔒
1437 Check If All 1's Are at Least Length K Places Away Easy O(N) O(1) Array
1438 Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit Medium O(N) O(N) Array, Queue, Sliding Window, Heap, Ordered Set, Monotonic Queue
1441 Build an Array With Stack Operations Easy O(N) O(N) Pythonic
1442 Count Triplets That Can Form Two Arrays of Equal XOR Medium O(N) O(N) Array, Math, Bit Manipulation
1443 Minimum Time to Collect All Apples in a Tree Medium O(E) O(E) Tree, DFS
1444 Number of Ways of Cutting a Pizza Hard O(K*R*C*(R+C)) O(K*R*C) Dynamic Programming
1446 Consecutive Characters Easy O(N) O(1) String
1447 Simplified Fractions Medium Varying Varying
1448 Count Good Nodes in Binary Tree Medium O(N) O(H) Tree, DFS
1450 Number of Students Doing Homework at a Given Time Easy O(N) O(1)
1451 Rearrange Words in a Sentence Medium O(N * logN) O(1) String, Sort
1452 People Whose List of Favorite Companies Is Not a Subset of Another List Medium O(N^2) O(N) String, Sort There is a better solution
1455 Check If a Word Occurs As a Prefix of Any Word in a Sentence Medium O(N) O(1) String, Pythonic
1456 Maximum Number of Vowels in a Substring of Given Length Medium O(N) O(1) String, Sliding Window
1457 Pseudo-Palindromic Paths in a Binary Tree Medium O(N) O(H) Bit Manipulation, Tree, DFS
1460 Make Two Arrays Equal by Reversing Sub-arrays Easy O(N) O(1) Array
1461 Check If a String Contains All Binary Codes of Size K Medium O(N) O(2**K) String, Bit Manipulation
1463 Cherry Pickup II Hard O(R*C*C) O(R*C*C) Array, Dynamic Programming, Matrix
1464 Maximum Product of Two Elements in an Array Easy O(N) O(1) Array
1465 Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts Medium O(NlogN) O(N) Array
1466 Reorder Routes to Make All Paths Lead to the City Zero Medium O(|V|) O(|V|) Tree, DFS
1470 Shuffle the Array Easy O(N) O(N) Array There is a better solution
1471 The k Strongest Values in an Array Medium O(NlogN) O(N) Array, Sort There is a better solution
1472 Design Browser History Medium O(1) O(1) Design
1474 Delete N Nodes After M Nodes of a Linked List Easy O(N) O(1) Linked List, Premium 🔒
1475 Final Prices With a Special Discount in a Shop Easy O(N) O(1) Monotonic Stack
1476 Subrectangle Queries Easy Varying Varying Design
1480 Running Sum of 1d Array Easy O(N) O(1)
1481 Least Number of Unique Integers after K Removals Medium O(NlogN) O(N) Array, Sort
1482 Minimum Number of Days to Make m Bouquets Medium O(NlogN) O(N) Array, Binary Search
1486 XOR Operation in an Array Easy O(1) O(1) Bit Manipulation
1491 Average Salary Excluding the Minimum and Maximum Salary Easy O(N) O(1)
1492 The kth Factor of n Medium O(logN) O(logN) Math, Tricky
1493 Longest Subarray of 1's After Deleting One Element Medium O(N) O(1) Array
1496 Path Crossing Easy O(N) O(N) String
1502 Can Make Arithmetic Progression From Sequence Easy O(NlogN) O(1) Array
1507 Reformat Date Easy O(1) O(1) String
1508 Range Sum of Sorted Subarray Sums Medium O(N^2logN) O(N^2)
1509 Minimum Difference Between Largest and Smallest Value in Three Moves Medium O(NlogN) O(1)
1510 Stone Game IV Hard O(N*N^0.5) O(N) Dynamic Programming
1512 Number of Good Pairs Easy O(N) O(N)
1513 Number of Substrings With Only 1s Medium O(N) O(N) String, Math
1518 Water Bottles Easy O(1) O(1) Greedy, Simulation
1519 Number of Nodes in the Sub-Tree With the Same Label Medium O(N) O(N) Hash Table, Tree, Depth-First Search, Breadth-First Search, Counting
1523 Count Odd Numbers in an Interval Range Easy O(1) O(1) Math
1524 Number of Sub-arrays With Odd Sum Medium O(N) O(1) Array, Math, Dynamic Programming
1525 Number of Good Ways to Split a String Medium O(N) O(N) String
1528 Shuffle String Easy O(N) O(N) String
1529 Bulb Switcher IV Medium O(N) O(1) String
1530 Number of Good Leaf Nodes Pairs Medium O(N^2logN) O(N) Tree, DFS
1533 Find the Index of the Large Integer Medium O(logN) O(1) Premium, Binary Search 🔒
1534 Count Good Triplets Easy O(N^3) O(1) Array, Enumeration
1535 Find the Winner of an Array Game Medium O(N) O(1) Array
1539 Kth Missing Positive Number Easy O(logN) O(1) Binary Search
1544 Make The String Great Easy O(N) O(N) String, Stack
1545 Find Kth Bit in Nth Binary String Medium O(N^2) O(N^2) String Not Optimal
1550 Three Consecutive Odds Easy O(N) O(1) Array
1551 Minimum Operations to Make Array Equal Medium O(1) O(1) Math
1552 Magnetic Force Between Two Balls Medium O(NlogN) O(1) Binary Search Template for Binary Search
1556 Thousand Separator Easy O(N) O(N) String
1557 Minimum Number of Vertices to Reach All Nodes Medium O(N) O(N) Graph
1558 Minimum Numbers of Function Calls to Make Target Array Medium O(NlogK) O(N) Greedy, Simulation
1560 Most Visited Sector in a Circular Track Easy O(N) O(1) Array
1561 Maximum Number of Coins You Can Get Medium O(N) O(1) Sort
1564 Put Boxes Into the Warehouse I Medium O(NlogN) O(N) Greedy 🔒
1566 Detect Pattern of Length M Repeated K or More Times Easy O(N) O(1) Array
1572 Matrix Diagonal Sum Easy O(N) O(1) Array
1573 Number of Ways to Split a String Medium O(N) O(N) String
1576 Replace All ?'s to Avoid Consecutive Repeating Characters Easy O(N) O(N) String
1578 Minimum Deletion Cost to Avoid Repeating Letters Medium O(N) O(1) Greedy
1580 Put Boxes Into the Warehouse II Medium O(NlogN) O(N) Greedy 🔒
1582 Special Positions in a Binary Matrix Easy O(N) O(N) Array
1583 Count Unhappy Friends Medium O(N^2) O(N^2) Array
1588 Sum of All Odd Length Subarrays Easy O(N) O(1) Array
1592 Rearrange Spaces Between Words Easy O(N) O(N) String
1598 Crawler Log Folder Easy O(N) O(1) Stack
1600 Throne Inheritance Medium O(N) O(N) Tree, Design
1602 Find Nearest Right Node in Binary Tree Medium O(N) O(N) Premium, Tree, BFS 🔒
1604 Alert Using Same Key-Card Three or More Times in a One Hour Period Medium O(NlogN) O(N) String, Ordered Map
1605 Find Valid Matrix Given Row and Column Sums Medium O(NM) O(NM) Greedy
1608 Special Array With X Elements Greater Than or Equal X Easy O(NlogN) O(N) Binary Search, Array
1609 Even Odd Tree Easy O(N) O(N) Tree
1614 Maximum Nesting Depth of the Parentheses Easy O(N) O(1) String
1615 Maximal Network Rank Medium O(N) O(1) Graph
1618 Maximum Font to Fit a Sentence in a Screen Medium O(logN) O(1) Premium, String, Binary Search 🔒
1624 Largest Substring Between Two Equal Characters Easy O(N) O(1) String
1625 Lexicographically Smallest String After Applying Operations Medium O(N*N) O(N) BFS, DFS
1629 Slowest Key Easy O(N) O(1) String
1631 Path With Minimum Effort Medium O(N*M*logH) O(M*N) Binary Search, DFS, BFS, Union Find, Graph
1632 Rank Transform of a Matrix Hard O(NlogN) O(N) Array, Greedy, Union Find, Graph, Topological Sort, Matrix
1634 Add Two Polynomials Represented as Linked Lists Medium O(N) O(1) Premium, Linked List 🔒
1639 Number of Ways to Form a Target String Given a Dictionary Hard O(N*M) O(N*M) Dynamic Programming
1640 Check Array Formation Through Concatenation Medium O(N) O(N) Array
1641 Count Sorted Vowel Strings Medium O(N) O(1) Dynamic Programming, Math, Backtracking
1642 Furthest Building You Can Reach Medium O(NlogN) O(N) Binary Search, Heap
1644 Lowest Common Ancestor of a Binary Tree II Medium O(N) O(H) Premium, Tree 🔒
1646 Get Maximum in Generated Array Easy O(N) O(N) Array
1647 Minimum Deletions to Make Character Frequencies Unique Medium O(1) O(1) Greedy, Sort
1650 Lowest Common Ancestor of a Binary Tree III Medium O(H) O(1) Premium, Tree 🔒
1652 Defuse the Bomb Medium O(N) O(N) Array
1653 Minimum Deletions to Make String Balanced Medium O(N) O(N) Greedy, String
1656 Design an Ordered Stream Easy O(N) O(N) Array, Design
1657 Determine if Two Strings Are Close Medium O(N) O(1) Greedy
1658 Minimum Operations to Reduce X to Zero Medium O(N) O(N) Greedy, Sliding Window
1663 Smallest String With A Given Numeric Value Medium O(N) O(1) Greedy
1664 Ways to Make a Fair Array Medium O(N) O(1) Dynamic Programming, Greedy
1673 Find the Most Competitive Subsequence Medium O(N) O(K) Stack, Heap, Greedy, Queue
1675 Minimize Deviation in Array Hard O(NlogN) O(N) Array, Greedy, Heap, Ordered Set
1679 Max Number of K-Sum Pairs Medium O(N) O(N) Hash Table
1684 Count the Number of Consistent Strings Easy O(N) O(1) String
1685 Sum of Absolute Differences in a Sorted Array Medium O(N) O(N) Math, Greedy
1690 Stone Game VII Medium O(N^2) O(N^2) Dynamic Programming
1695 Maximum Erasure Value Medium O(N) O(1) Two Pointers
1696 Jump Game VI Medium O(N) O(N) Dequeue Dequeue, Monotonic Dequeue
1700 Number of Students Unable to Eat Lunch Medium O(N) O(1) Array
1705 Maximum Number of Eaten Apples Medium O(NlogN) O(N) Heap, Greedy
1706 Where Will the Ball Fall Medium O(N*M) O(M) Dynamic Programming
1710 Maximum Units on a Truck Medium O(NlogN) O(N) Greedy, Sort
1716 Calculate Money in Leetcode Bank Easy O(N) O(1) Math, Greedy
1721 Swapping Nodes in a Linked List Medium O(N) O(1) Linked List
1725 Number Of Rectangles That Can Form The Largest Square Easy O(N) O(1) Greedy
1726 Tuple with Same Product Medium O(N^2) O(N) Array, Hash Table
1732 Find the Highest Altitude Easy O(N) O(1) Array
1736 Latest Time by Replacing Hidden Digits Easy O(1) O(1) String, Greedy
1748 Sum of Unique Elements Easy O(N) O(N) Array, Hash Table
1749 Maximum Absolute Sum of Any Subarray Medium O(N) O(1) Greedy
1750 Minimum Length of String After Deleting Similar Ends Medium O(N) O(1) Two Pointers
1752 Check if Array Is Sorted and Rotated Easy O(N) O(1) Array
1753 Maximum Score From Removing Stones Medium O(1) O(1) Math, Heap
1758 Minimum Changes To Make Alternating Binary String Easy O(N) O(1) Array, Greedy
1759 Count Number of Homogenous Substrings Medium O(N) O(1) String, Greedy
1763 Longest Nice Substring Easy O(NlogN) O(N) String
1764 Form Array by Concatenating Subarrays of Another Array Medium O(N+M) O(M) Array, Greedy KMP Algorithm
1765 Map of Highest Peak Medium O(N*M) O(N*M) BFS, Graph
1768 Merge Strings Alternately Easy O(N) O(N) String
1769 Minimum Number of Operations to Move All Balls to Each Box Medium O(N) O(N) Array, Greedy
1773 Count Items Matching a Rule Easy O(N) O(1) Array, String
1774 Closest Dessert Cost Medium O(N*M*V) O(M*V) Greedy
1779 Find Nearest Point That Has the Same X or Y Coordinate Easy O(N) O(1) Array
1780 Check if Number is a Sum of Powers of Three Medium O(logN) O(1) Math, Backtracking, Recursion
1781 Sum of Beauty of All Substrings Medium O(N^2) O(1) Hash Table, String
1784 Check if Binary String Has at Most One Segment of Ones Easy O(N) O(1) Greedy
1791 Find Center of Star Graph Medium O(1) O(1) Graph
1792 Maximum Average Pass Ratio Medium O(N+KlogN) O(N) Heap
1797 Design Authentication Manager Medium O(Design) O(N) Hash Table, Design
1807 Evaluate the Bracket Pairs of a String Medium O(N) O(1) Array, Hash Table, String
1812 Determine Color of a Chessboard Square Easy O(1) O(1) Math, String
1816 Truncate Sentence Easy O(N) O(1) String
1818 Minimum Absolute Sum Difference Medium O(NlogN) O(sort) Binary Search, Greedy
1827 Minimum Operations to Make the Array Increasing Easy O(N) O(1) Array, Greedy
1828 Queries on Number of Points Inside a Circle Medium O(N*M) O(M) Math
1832 Check if the Sentence Is Pangram Easy O(N) O(1) String
1833 Maximum Ice Cream Bars Medium O(NlogN) O(sort) Array, Sort
1837 Sum of Digits in Base K Medium O(logN) O(1) Math, Bit Manipulation
1839 Longest Substring Of All Vowels in Order Medium O(N) O(1) Two Pointers, String
1844 Replace All Digits with Characters Easy O(N) O(N) String
1845 Seat Reservation Manager Medium O(logN) O(N) Heap, Design
1846 Maximum Element After Decreasing and Rearranging Medium O(N) O(N) Array, Greedy, Sorting
1848 Minimum Distance to the Target Element Easy O(N) O(1) Array
1854 Maximum Population Year Easy O(NlogN) O(N) Array, Counting
1859 Sorting the Sentence Easy O(N) O(N) String, Sorting
1860 Incremental Memory Leak Medium O(logN) O(1) Math
1861 Rotating the Box Medium O(R*C) O(1) Array, Two Pointers
1864 Minimum Number of Swaps to Make the Binary String Alternating Medium O(N) O(N) String, Greedy
1877 Minimize Maximum Pair Sum in Array Medium O(NlogN) O(Sort) Array, Two Pointers, Greedy, Sorting
1897 Redistribute Characters to Make All Strings Equal Easy O(N) O(N) Hash Table, String, Couting
1899 Merge Triplets to Form Target Triplet Medium O(N) O(1) Greedy, Array
1903 Largest Odd Number in String Easy O(N) O(1) Math, String, Greedy
1905 Count Sub Islands Medium O(R*C) O(R*C) Array, DFS, BFS, Union-Find, Matrix
1911 Maximum Alternating Subsequence Sum Medium O(N) O(1) Array, Dynamic Programming, Greedy
1920 Build Array from Permutation Easy O(N) O(1) Array, Simulation
1929 Concatenation of Array Easy O(N) O(1) Array
1962 Remove Stones to Minimize the Total Medium O(KlogN) O(N) Array, Heap
1963 Minimum Number of Swaps to Make the String Balanced Medium O(N) O(1) Two Pointers,String,Stack,Greedy
1971 Find if Path Exists in Graph Easy O(N) O(N) BFS, DFS, Graph
1974 Minimum Time to Type Word Using Special Typewriter Easy O(N) O(1) String, Greedy
1980 Find Unique Binary String Medium O(NlogN) O(N) String, Binary Search
1991 Find the Middle Index in Array Easy O(N) O(N) Array, Prefix Sum
1992 Find All Groups of Farmland Medium O(R*C) O(R*C) Array, DFS, BFS, Matrix
1995 Count Special Quadruplets Easy O(N^2) O(N^2) Array, Enumeration
1996 The Number of Weak Characters in the Game Medium O(NlogN) O(N) Array, Stack, Greedy, Sorting, Monotonic Stack
2000 Reverse Prefix of Word Easy O(N) O(1) Two Pointers, String
2024 Maximize the Confusion of an Exam Medium O(N) O(1) String, Binary Search, Sliding Window, Prefix Sum
2038 Remove Colored Pieces if Both Neighbors are the Same Color Medium O(N) O(1) Math, String, Greedy, Game Theory
2039 The Time When the Network Becomes Idle Medium O(V+E) O(V+E) Array, BFS, Graph
2042 Check if Numbers Are Ascending in a Sentence Easy O(N) O(1) String
2043 Simple Bank System Medium Design Design Array, Hash Table, Design, Simulation
2049 Count Nodes With the Highest Score Medium O(N) O(N) Array, Tree, Depth-First Search, Binary Tree
2062 Count Vowel Substrings of a String Easy O(N^3) O(N) Hash Table, String
2073 Time Needed to Buy Tickets Easy O(N) O(1) Array, Queue, Simulation
2074 Reverse Nodes in Even Length Groups Medium O(N) O(N) Linked List
2085 Count Common Words With One Occurrence Easy O(N) O(N) Array, Hash Table, String, Counting
2087 Minimum Cost Homecoming of a Robot in a Grid Medium O(N) O(1) Array, Greedy, Matrix
2091 Removing Minimum and Maximum From Array Medium O(N) O(1) Greedy, Array
2094 Finding 3-Digit Even Numbers Easy O(N) O(N) Array, Hash Table, Sorting, Enumeration
2095 Delete the Middle Node of a Linked List Medium O(N) O(1) Linked List
2096 Step-By-Step Directions From a Binary Tree Node to Another Medium O(N) O(N) String, Tree, Depth-First Search, Binary Tree
2099 Find Subsequence of Length K With the Largest Sum Medium O(NlogK) O(K) Array, Hash Table, Sotring, Heap
2100 Array, Dynamic Programming, Prefix Sum Medium O(N) O(N) Array, Dynamic Programming, Prefix Sum
2101 Detonate the Maximum Bombs Medium O(E+V) O(E+V) Array, Math, DFS, BFS, Graph, Geometry
2103 Rings and Rods Easy O(N) O(N) Hash Table, String
2119 A Number After a Double Reversal Easy O(1) O(1) Math
2120 Execution of All Suffix Instructions Staying in a Grid Medium O(S) O(S) String, Simulation
2121 Intervals Between Identical Elements Medium O(N) O(N) Array, Hash Table, Prefix Sum
2136 Earliest Possible Day of Full Bloom Hard O(Sort) O(Sort) Array, Greedy, Sorting
2138 Divide a String Into Groups of Size k Easy O(N) O(N) String, Simulation
2139 Minimum Moves to Reach Target Score Medium O(logN) O(1) Math, Greedy
2140 Solving Questions With Brainpower Medium O(N) O(N) Array, Dynamic Programming
2165 Smallest Value of the Rearranged Number Medium O(logN) O(logN) Math, Sorting
2176 Count Equal and Divisible Pairs in an Array Easy O(N^2) O(1) Array
2177 Find Three Consecutive Integers That Sum to a Given Number Medium O(1) O(1) Math, Binary Search
2180 Count Integers With Even Digit Sum Easy O(1) O(1) Math, Simulation
2185 Counting Words With a Given Prefix Easy O(N) O(1) Array, String
2186 Minimum Number of Steps to Make Two Strings Anagram II Medium O(N) O(N) Hash Table, String, Counting
2190 Most Frequent Number Following Key In an Array Easy O(N) O(N) Array, Hash Table, Counting
2191 Sort the Jumbled Numbers Medium O(NlogN) O(1) Array, Sorting
2192 All Ancestors of a Node in a Directed Acyclic Graph Medium O(N+V) O(U+V) DFS, BFS, Topological Sort, Graph
2196 Create Binary Tree From Descriptions Medium O(N) O(N) DFS, BFS, Binary Tree, Tree, Hash Table, Array
2244 Minimum Rounds to Complete All Tasks Medium O(N) O(N) Array, Hash Table, Greedy, Counting
2270 Number of Ways to Split Array Medium O(N) O(N) Array, Prefix Sum
2303 Calculate Amount Paid in Taxes Easy O(N) O(1) Array, Simulation
2336 Smallest Number in Infinite Set Medium O(Design) O(Design) Hash Table, Design, Heap (Priority Queue)
2347 Best Poker Hand Easy O(1) O(1) Array, Hash Table, Counting
2359 Find Closest Node to Given Two Nodes Medium O(N) O(N) DFS, Graph
2368 Reachable Nodes With Restrictions Medium O(V + E) O(V + E) Array, Hash Table, Tree, BFS, DFS, Graph
2370 Longest Ideal Subsequence Medium O(N) O(N) Hash Table, String, Dynamic Programming
2389 Longest Subsequence With Limited Sum Easy O(NlogN) O(N) Array, Binary Search, Greedy, Sorting, Prefix Sum
2476 Closest Nodes Queries in a Binary Search Tree Medium O(NlogN) O(N) Array, Binary Search, Tree, Depth-First Search, Binary Search Tree, Binary Tree
2487 Remove Nodes From Linked List Medium O(N) O(N) Linked List, Stack, Recursion, Monotonic Stack
2498 Frog Jump II Medium O(N) O(1) Array, Binary Search, Greedy
2502 Design Memory Allocator Medium Design Design Array, Hash Table, Design, Simulation
2517 Maximum Tastiness of Candy Basket Medium O(NlogN) O(1) Array, Binary Search, Sorting
2571 Minimum Operations to Reduce an Integer to 0 Medium O(logN) O(logN) Dynamic Programming, Greedy, Bit Manipulation
2583 Kth Largest Sum in a Binary Tree Medium O(NlogN) O(N) Tree, Breadth-First Search, Sorting, Binary Tree
2641 Cousins in Binary Tree II Medium O(N) O(N) Hash Table, Tree, Depth-First Search, Breadth-First Search, Binary Tree
2673 Make Costs of Paths Equal in a Binary Tree Medium O(N) O(logN) Array, Dynamic Programming, Greedy, Tree, Binary Tree
2812 Find the Safest Path in a Grid Medium O(R*C) O(R*C) Array, Binary Search, Breadth-First Search, Union Find, Matrix
2824 Count Pairs Whose Sum is Less than Target Easy O(NlogN) O(1) Array, Two Pointers, Binary Search, Sorting
2958 Length of Longest Subarray With at Most K Frequency Medium O(N) O(N) Array, Hash Table, Sliding Window
2962 Count Subarrays Where Max Element Appears at Least K Times Medium O(N) O(N) Array, Sliding Window
2966 Divide Array Into Arrays With Max Difference Medium O(NlogN) O(N) Array, Greedy, Sorting
2971 Find Polygon With the Largest Perimeter Medium O(N) O(N) Array, Greedy, Sorting, Prefix Sum
3005 Count Elements With Maximum Frequency Easy O(N) O(N) Array, Hash Table, Counting
3075 Maximize Happiness of Selected Children Medium O(NlogK) O(K) Array, Greedy, Sorting
3083 Existence of a Substring in a String and Its Reverse Easy O(N) O(N) Hash Table, String
3084 Count Substrings Starting and Ending with Given Character Medium O(N) O(1) Math, String, Counting
3085 Minimum Deletions to Make String K-Special Medium O(N) O(1) Hash Table, String, Greedy, Sorting, Counting
3090 Maximum Length Substring With Two Occurrences Easy O(N) O(1) Hash Table, String, Sliding Window
3091 Apply Operations to Make Sum of Array Greater Than or Equal to k Medium O(1) O(1) Math, Greedy, Enumeration
3092 Most Frequent IDs Medium O(NlogN) O(N) Array, Hash Table, Heap (Priority Queue), Ordered Set Template for Sorted Container
3105 Longest Strictly Increasing or Strictly Decreasing Subarray Easy O(N) O(1)
3106 Lexicographically Smallest String After Operations With Constraint Medium O(N) O(N)
3107 Minimum Operations to Make Median of Array Equal to K Medium O(NlogN) O(N)

Useful Posts

Syntax

Dynamic Programming

System Design

LP

Others

List

About

This list contains solutions to most questions I have solved on LeetCode

Topics

Resources

Stars

Watchers

Forks

Languages