Solutions to some algorithm problems. (Mainly from leetcode)
This repository is mainly for personal use, however, it's licensed under AGPL-v3.
So use it as free as you can.
*. Time complexity is calculated using the worst case (i.e. all hash conflict)
Language Used
Abbreviation | Language | Usage |
---|---|---|
CPP |
C++ | Mainly for Hard and Medium Problems |
CS |
C# / CSharp | Mainly for Medium and Easy Problems |
TS |
TypeScript | Mainly for Easy Problems |
PY |
Python | Legacy |
Problem List
ID | Problem | Solution Adopted | Perceived Difficulty | Annotated Difficulty | Time Complxity | Lang | Status |
---|---|---|---|---|---|---|---|
1 | Two Sum | Hash | 1 | EASY | O(nlogn) | CPP |
L |
2 | Add Two Numbers | Simulation | 1 | MEDIUM | O(n) | CPP |
L |
3 | Longest Substring Without Repeating Characters | Sliding Window | 1 | MEDIUM | O(n) | CPP |
L |
4 | Median of Two Sorted Arrays | Binary Search | 7 ★ | HARD | O(logn) | CPP |
|
5 | Longest Palindromic Substring | Manacher | 4 | MEDIUM | O(n) | CPP |
|
6 | Zigzag Conversion | Simulation | 2 | MEDIUM | O(n) | CPP |
L |
7 | Reverse Integer | Simulation | 0 | MEDIUM | O(logn) | CPP |
L |
8 | String to Integer | Simulation | 0 | MEDIUM | O(n) | CS |
|
9 | Palindrome Number | Simulation | 0 | EASY | O(logn) | CPP |
L |
10 | Regular Expression Matching | Dynamic Programming | 5 | HARD | CPP |
||
11 | Container with Most Water | Two Pointers | 7 ★ | MEDIUM | O(n) | CS |
|
12 | Integer to Roman | Simulation | 0 | MEDIUM | O(logn) | CS |
|
13 | Roman to Integer | Simulation | 0 | EASY | O(n) | CPP |
L |
14 | Longest Common Prefix | Simulation | 0 | EASY | O(nm) | CPP |
L |
15 | 3 Sum | Hash | 5 | MEDIUM | O(n^3) | CS |
|
16 | 3 Sum Closest | Two Pointers | 5 | MEDIUM | O(n^2) | CS |
|
17 | Letter Combinations of a Phone Number | Simulation | 0 | MEDIUM | O(n*4^n) | CS |
|
18 | 4 Sum | Two Pointers | 5 | MEDIUM | O(n^3) | CS |
|
19 | Remove Nth Node From End of List | Two Pointers | 3 | MEDIUM | O(n) | CS |
|
20 | Valid Parentheses | Stack | 0 | EASY | O(n) | CPP |
L |
21 | Merge Two Sorted Lists | Simulation | 0 | EASY | O(n) | CPP |
L |
22 | Generate Parentheses | Simulation | 1 | MEDIUM | / | CS |
|
23 | Merge k Sorted Lists | Simulation | 1 | HARD | CPP |
||
24 | Swap Nodes in Pairs | Simulation | 2 | MEDIUM | O(n) | CS |
|
25 | Reverse Nodes in k-Group | Simulation | 3 | HARD | CPP |
||
26 | Remove Duplicates From Sorted Array | Two Pointers | 1 | EASY | O(n) | CPP |
L |
27 | Remove Element | Two Pointers | 2 | EASY | O(n) | CPP |
L |
28 | Find the Index of the First Occurrence in a String | / (Expected KMP) | 2 | EASY | O(n) | PY |
L |
29 | Divide | Binary Calculation | 5 | MEDIUM | O(logn) | CS |
|
30 | Substring with Concatenation of All Words | Sliding Window | 6 | HARD | CPP |
||
31 | Next Permutation | Sort | 5 | MEDIUM | O(n^2) | CS |
T |
32 | Longest Valid Parentheses | Dynamic Programming + Stack | 4 | HARD | CPP |
||
33 | Search in Rotated Sorted Array | Binary Search | 3 | MEDIUM | O(nlogn) | CS |
|
34 | Find First and Last Position of Element in Sorted Array | Binary Search | 2 | MEDIUM | O(nlogn) | CS |
|
35 | Search Insert Position | Binary Search | 1 | EASY | O(logn) | CPP |
L |
36 | Valid Sudoku | Simulation | 1 | MEDIUM | CS |
||
37 | Sudoku Solver | Simulation | 2 | HARD | / | CPP |
|
38 | Count And Say | Simulation | 1 | MEDIUM | O(n^2) | CPP |
L |
39 | Combination Sum | Dynamic Programming + Depth First Search | 4 | MEDIUM | / | CS |
|
40 | Combination Sum II | Dynamic Programming + Depth First Search | 4 | MEDIUM | / | CS |
|
41 | First Missing Positive | Simulation (Inplace) | 8 ★ | HARD | CPP |
||
42 | Trapping Rain Water | Simulation | 4 | HARD | CPP |
||
43 | Multiply String | Simulation | 2 | MEDIUM | O(n^2) | CS |
|
44 | Wildcard Matching | Dynamic Programming | N/A | HARD | CPP |
T | |
45 | Jump Game II | Dynamic Programming / Greedy Search / Simulation | 4 | MEDIUM | O(n) | CS |
|
46 | Permutations | Simulation | 0 | MEDIUM | O(n!) | CS |
|
47 | Permutations II | Simulation+Sort | 2 | MEDIUM | O(n!) | CS |
|
48 | Rotate Image | Simulation | 3 | MEDIUM | O(n^2) | CS |
|
49 | Group Anagrams | Hash | 4 | MEDIUM | O(n^2m) | CS |
|
50 | Pow(x,n) | Fast Power Algorithm | 3 | MEDIUM | CPP |
||
51 | N-Queens | Simulation | 1 | HARD | CPP |
||
52 | N-Queens II | Simulation | 0 | HARD | CPP |
||
53 | Maximum Subarray | Prefix Sum & Greedy Simulation | 2 | MEDIUM | O(n) | CPP |
LT |
54 | Spiral Matrix | Simulation | 2 | MEDIUM | O(n^2) | CPP |
L |
55 | Jump Game | Simulation | 2 | MEDIUM | O(n) | CS |
|
56 | Merge Intervals | Sort | 2 | MEDIUM | O(nlogn) | CS |
|
57 | Insert Intervals | Simulation + Binary Search (optional) | 4 | MEDIUM | O(n) | CS |
|
58 | Length of Last Word | Simulation | 0 | EASY | O(n) | CPP |
L |
59 | Spiral Matrix II | Simulation | 2 | MEDIUM | O(n^2) | CPP |
L |
60 | Permutation Sequence | Combinatorics | 5 | HARD | CPP |
||
61 | Rotate List | Simulation | 2 | MEDIUM | O(n) | CPP |
L |
62 | Unique Paths | Dynamic Programming | 0 | MEDIUM | O(nm) | CS |
|
63 | Unique Paths II | Dynamic Programming | 0 | MEDIUM | O(nm) | CS |
|
64 | Minimum Path Sum | Dynamic Programming | 0 | MEDIUM | O(nm) | CS |
|
65 | Valid Number | Simulation | 2 | HARD | CPP |
||
66 | Plus One | Simulation | 1 | EASY | O(n) | CPP |
L |
67 | Add Binary | Simulation | 1 | EASY | O(n) | CPP |
L |
68 | Text Justification | Simulation | 2 | HARD | CPP |
||
69 | Sqrt(X) | Binary Search | 1 | EASY | O(logn) | CPP |
LT |
70 | Climbing Stairs | Dynamic Programming | 0 | EASY | CPP |
||
71 | Simplify Path | Stack | 1 | MEDIUM | O(n) | CS |
|
72 | Edit Distance | Dynamic Programming | 6 | MEDIUM | O(n^3) | CS |
T |
73 | Set Matrix Zeros | Simulation + Intuition | 2 | MEDIUM | O(mn) | CPP |
L |
74 | Search A 2D Matrix | Simulation | 2 | MEDIUM | O(m+n) | CPP |
LT |
75 | Sort Colors | Two Pointers | 4 | MEDIUM | O(n) | CS |
|
76 | Minimum Window Substring | Sliding Window | 6 | HARD | CPP |
||
77 | Combinations | Simulation | 2 | MEDIUM | / | CS |
|
78 | Subsets | Simulation | 1 | MEDIUM | O(2^n) | CS |
|
79 | Word Search | Simulation | 1 | MEDIUM | O(n^2*m^2) | CS |
T |
80 | Remove Duplicates From Sorted Array II | Simulation (Two Pointers) | 3 | MEDIUM | CS |
L | |
81 | Search In Rotated Sorted Array II | Simulataion | N/A | MEDIUM | CS |
LT | |
82 | Remove Duplicates From Sorted Array II | Simulation (Two Pointers) | 2 | MEDIUM | CPP |
L | |
83 | Remove Duplicates From Sorted Array | Simulation (Two Pointers) | 1 | EASY | CPP |
L | |
84 | Largest Rectangle in Histogram | Stack | 6 | HARD | CPP |
||
85 | Maximal Rectangle | Prefix Sum | 5 | HARD | CPP |
||
86 | Partition List | Simulation | 1 | MEDIUM | O(n) | CS |
|
87 | Scramble String | Dynamic Programming + Intuition | 7 ★ | HARD | O(n^4) | CPP |
|
88 | Merge Sorted Array | Simulation (Two Pointers) | 1 | EASY | O(n) | CS |
|
89 | Gray Code | Intuition + Simulation | 4 | MEDIUM | O(2^n) | CS |
|
90 | Subsets II | Simulation | 2 | MEDIUM | CPP |
L | |
91 | Decode Ways | Dynamic Programming | 1 | MEDIUM | O(n) | CS |
|
92 | Reverse Linked List | Simulation | 2 | MEDIUM | O(n) | CPP |
L |
93 | Restore IP Address | Simulation | 1 | MEDIUM | / | CS |
|
94 | Binary Tree Mid Order Traversal | Simulation | 1 | EASY | CPP |
L | |
95 | Unique Binary Search Trees II | Simulation | 4 | MEDIUM | / | CPP |
|
96 | Unique Binary Search Trees | Dynamic Programming | 2 | MEDIUM | O(n^2) | CS |
|
97 | Interleaving String | Dynamic Programming | 6 | MEDIUM | / | / | |
97F | Interleaving String (Follow-up) | Dynamic Programming (Scrolling Array) | 6 | MEDIUM | O(n^2) | CPP |
|
98 | Validate Binary Search Tree | Simulation | 1 | MEDIUM | O(n) | CS |
|
99 | Recover Binary Search Tree | Inorder Traversal | 5 | MEDIUM | O(n) | CPP |
|
99F | Recover Binary Search Tree (Follow-up) | Inorder Traversal + Simulation | 5 | MEDIUM | O(n) | CPP |
|
100 | Same Tree | Simulation | 0 | EASY | O(n) | CPP |
L |
101 | Symmetric Tree | Simulation | 1 | EASY | O(n) | CPP |
|
102 | Binary Tree Level Order Traversal | Simulation | 0 | MEDIUM | O(n) | CPP |
L |
103 | Binary Tree Zig-zag Level Order Traversal | Simulation | 1 | MEDIUM | O(n) | CPP |
|
104 | Maximum Depth of Binary Tree | Depth-first Search | 0 | EASY | O(n) | CS |
|
105 | Construct Binary Tree from Preorder and Inorder Traversal | Simulation | 1 | MEDIUM | O(n) | CPP |
|
106 | Construct Binary Tree from Inorder and Postorder Traversal | Simulation | 1 | MEDIUM | O(n) | CPP |
|
107 | Binary Tree Level Order Traversal II | Simulation | 0 | MEDIUM | O(n) | CPP |
|
108 | Convert Sorted Array to Binary Search Tree | Divide & Conquer | 1 | MEDIUM | O(n) | CPP |
|
109 | Convert Sorted List to Binary Search Tree | Inorder Traversal | 4 | MEDIUM | O(n) | CPP |
|
110 | Balanced Binary Tree | Simulation | 0 | EASY | O(n) | CPP |
|
111 | Minimum Depth of Binary Tree | Simulation | 0 | EASY | O(n) | CPP |
|
112 | Path Sum | Simulation | 0 | EASY | O(n) | CPP |
|
113 | Path Sum II | Simulation | 0 | MEDIUM | / | CPP |
|
114 | Flatten Binary Tree To Linked List | Simulation | N/A | MEDIUM | O(n) | CS |
T |
115 | Distinct Subsequences | Dynamic Programming | 5 | HARD | / | CPP |
L |
116 | Populating Next Right Pointers in Each Node | BFS | 1 | MEDIUM | / | CPP |
P |
117 | Populating Next Right Pointers in Each Node II | Depth-first Search | 1 | MEDIUM | / | CPP |
|
117F | Populating Next Right Pointers in Each Node II (Follow-up) | Depth-first Search | 4 | MEDIUM | / | CPP |
|
118 | Pascal's Triangle | Dynamic Programming | 0 | EASY | O(n^2) | CPP |
|
119 | Pascal's Triangle II | Dynamic Programming | 0 | EASY | O(n^2) | CPP |
|
119F | Pascal's Triangle II (Follow-up) | Dynamic Programming (Scrolling Array) | 1 | EASY | O(n^2) | CPP |
|
120 | Triangle | Dynamic Programming | 1 | MEDIUM | O(n^2) | CS |
|
121 | Best Time to Buy and Sell Stock | Dynamic Programming | 0 | EASY | O(n) | CPP |
L |
122 | Best Time to Buy and Sell Stock II | Dynamic Programming | 1 | MEDIUM | O(n) | CS |
|
123 | Best Time to Buy and Sell Stock III | Dynamic Programming | 5 | HARD | CPP |
||
124 | Binary Tree Maximum Path Sum | Dynamic Programming | 3 | HARD | CPP |
||
125 | Valid Palindrome | Simulation | 0 | EASY | O(n) | CS |
|
126 | Word Ladder II | Breadth-first Search + Depth-first Search | 6 | HARD | / | CPP |
|
127 | Word Ladder | Breadth-first Search | 6 | HARD | O(n^2*m^2) | CPP |
|
128 | Longest Consecutive Sequence | Hashing + Union Find Algorithm | 4 | MEDIUM | O(n^2) | CPP |
|
129 | Sum Root to Leaf Numbers | DFS | 0 | MEDIUM | O(n) | CPP |
|
130 | Surrounded Regions | Simulation | 1 | MEDIUM | O(nm) | CPP |
|
131 | Palindrome Partitioning | Simulation | 2 | MEDIUM | / | PY |
L |
132 | Palindrome Partitioning II | Simulation | 5 | HARD | / | CPP |
L |
133 | Clone Graph | DFS | 1 | MEDIUM | O(V^2E) | CPP |
|
134 | Gas Station | Greedy Strategy | 3 | MEDIUM | O(n) | CPP |
|
135 | Candy | Greedy Strategy + Sort | 4 | HARD | CPP |
||
136 | Single Number | Binary Calculation | 2 | EASY | O(n) | CPP |
L |
137 | Single Number II | Ternary Calculation | 3 | MEDIUM | O(nlogn) | CPP |
|
138 | Copy List with Random Pointers | Simulation | 1 | MEDIUM | O(n) | CPP |
|
139 | Word Break | Dynamic Programming + String Hash | 3 | MEDIUM | O(n^3) | CPP |
|
140 | Word Break II | Dynamic Programming + Depth-First Search + String Hash | 5 | HARD | CPP |
||
141 | Linked List Cycle | Simulation | 1 | EASY | / | / | |
141F | Linked List Cycle (Follow-up) | Two Pointers | 4 | EASY | O(n) | CPP |
|
142 | Linked List Cycle II | Simulation | 1 | MEDIUM | / | / | |
142F | Linked List Cycle II (Follow-up) | Two Pointers + Math | 6 | MEDIUM | O(n) | CPP |
|
143 | Reorder Linked List | Simulation | 1 | MEDIUM | O(n) | CPP |
S |
144 | Binary Tree Preorder Traversal | Simulation | 0 | EASY | O(n) | CPP |
L |
145 | Binary Tree Postorder Traversal | Simulation | 0 | EASY | O(n) | CPP |
L |
146 | LRU Cache | Hash + Double-Ended Queue | 3 | MEDIUM | O(n) | CPP |
|
147 | Insertion Sort List | Simulation | 1 | MEDIUM | O(n^2) | CPP |
|
148 | Sort List | Merge Sort | 3 | MEDIUM | O(nlogn) | CPP |
|
149 | Max Points on a Line | Simulation | 1 | HARD | O(n^3) | CS |
L |
150 | Evaluate Reverse Polish Notation | Stack | 1 | MEDIUM | O(n) | CPP |
L |
160 | Intersection of Two Linked Lists | Simulation | 1 | EASY | / | / | |
160F | Intersection of Two Linked Lists (Follow-up) | Simulation | 1 | EASY | O(n) | CPP |
|
172 | Factorial Trailing Zeroes | Simulation | 0 | MEDIUM | O(logn) | CS |
|
174 | Dungeon Game | Dynamic Programming | 7 ★ | HARD | CPP |
||
184 | Best Time to Buy and Sell Stock IV | Dynamic Programming | 5 | HARD | CPP |
||
189 | Rotate Array | Simulation | 1 | MEDIUM | / | / | |
189F | Rotate Array (Follow-up) | Simulation + Math | 3 | MEDIUM | O(n) | CPP |
|
199 | Binary Tree Right Side View | Simulation | 1 | MEDIUM | O(n) | CPP |
|
200 | Number of Islands | Breadth-first Search | 0 | MEDIUM | O(nm) | CS |
|
206 | Reversed Linked List | Simulation | 0 | EASY | O(n) | CPP |
|
207 | Course Schedule | Topological Sort | 0 | MEDIUM | O(n) | CS |
|
214 | Shortest Palindrome | Rabin-Karp | 4 | HARD | CPP |
||
218 | The Skyline Problem | Heap + Sort | 5 | HARD | CPP |
||
225 | Implement Stack Using Queues | Simulation | 0 | EASY | O(nm) | / | |
225F | Implement Stack Using Queues (Follow-up) | Simulation | 0 | EASY | O(nm) | CS |
|
226 | Invert Binary Tree | Simulation | 0 | EASY | O(n) | CPP |
|
230 | K-th Smallest Element in a BST | Inorder Traversal | 1 | MEDIUM | O(n) | CPP |
|
231 | Power of Two | Simulation | 0 | EASY | O(logn) | CS |
|
232 | Implement Queue using Stacks | Simulation | 0 | EASY | O(nm) | / | |
232F | Implement Queue using Stacks (Follow-up) | Simulation | 0 | EASY | O(n) | CS |
|
233 | Number of Digit One | Combinatorics + Dynamic Programming | 6 | HARD | CPP |
||
234 | Palindrome Linked List | Simulation | 0 | EASY | / | / | |
234F | Palindrome Linked List (Follow-up) | Simulation | 1 | EASY | O(n) | CPP |
|
236 | Lowest Common Ancestor of a Binary Tree | Simulation | 1 | MEDIUM | O(n) | CPP |
|
238 | Product of Array Except Self | Prefix Sum | 0 | MEDIUM | / | / | |
238F | Product of Array Except Self (Follow-up) | Prefix Sum | 1 | MEDIUM | O(n) | CPP |
|
273 | Integer To English Words | Simulation | 1 | HARD | O(n) | CPP |
|
282 | Expression Add Operators | Simulation | 2 | HARD | / | CPP |
|
283 | Move Zeroes | Two Pointers | 1 | EASY | O(n) | CS |
|
292 | Nim Game | Gaming Theory + Dynamic Programming | 3 | EASY | CPP |
||
295 | Find Median from Data Stream | Heap | 5 | HARD | CPP |
||
299 | Bulls and Cows | Simulation | 1 | MEDIUM | O(n) | CS |
|
297 | Serialize and Deserialize Binary Tree | Breadth-first Search | 2 | HARD | O(n) | CPP |
|
301 | Remove Invalid Parentheses | Depth-first Search | 6 | HARD | / | CPP |
|
303 | Range Sum Query Immutable | Prefix Sum | -1 | EASY | O(n) | CS |
|
310 | Minimum Height Tree | Dynamic Programming | 3 | MEDIUM | O(n) | CS |
|
312 | Burst Balloons | Dynamic Programming | 6 | HARD | CPP |
||
315 | Count of Smaller Numbers After Self | Binary Index Tree | 3 | HARD | CPP |
||
322 | Coin Change | Dynamic Programming | 1 | MEDIUM | O(nm) | CS |
|
327 | Count of Range Sum | Binary Index Tree + Hash + Binary Search Tree + Prefix Sum | 6 | HARD | CPP |
||
329 | Longest Increasing Path | Topological Sort | 4 | HARD | O(mn) | CPP |
|
330 | Patching Array | Greedy Strategy | 4 | HARD | CS |
T | |
375 | Verify Pre-order Serialization of a Binary Tree | Depth-first Search (DFS) | 1 | MEDIUM | O(n) | CS |
|
332 | Reconstruct Itinerary | Eulerian Circuit (Hierholzer Algorithm) + Greedy Strategy(Sort) + Hash | 8 ★ | HARD | O(n^2) | CPP |
|
367 | Valid Perfect Square | Binary Search | 0 | EASY | O(logn) | CPP |
|
375 | Guess Number Higher or Lower II | Dynamic Programming (Range) | 3 | MEDIUM | O(n^3) | CPP |
|
391 | Perfect Rectangle | Simulation + Intuition | 5 | HARD | O(nlogn) | CPP |
|
396 | Rotate Function | Simulation | 1 | MEDIUM | O(n) | CPP |
|
403 | Frog Jump | Breadth-first Search | 3 | HARD | CPP |
||
407 | Trapping Water II | Heap | 5 | HARD | O(nm*log(nm)) | CPP |
|
410 | Split Array Largest Sum | Dynamic Programming | N/A | HARD | CPP |
T | |
416 | Partition Equal Subset Sum | Dynamic Programming (Backpack Problem) | 1 | MEDIUM | O(n^3) | CS |
|
437 | Path Sum III | Prefix Sum + Hash | 3 | MEDIUM | O(n^2) | CPP |
|
438 | Find All Anagrams In a String | Sliding Window | 2 | MEDIUM | O(n) | CS |
|
440 | K-th Smallest in Lexicographical Order | Simulation | 5 | HARD | O(logn) | CPP |
|
446 | Arithmetic Slices II - Subsequence | Dynamic Programming + Hash | 5 | HARD | O(n^3) | CPP |
|
458 | Poor Pig | Math | 9 ★ | HARD | Depend on std implementation |
CPP |
|
467 | Unique Substrings in Wraparound String | Dynamic Programming | 1 | MEDIUM | O(n) | CS |
|
472 | Concatenated Words | Trie + Depth-first Search | 6 | HARD | / | CPP |
|
474 | Ones And Zeros | Dynamic Programming (Backpack) | 2 | MEDIUM | O(mnp+pq) | CS |
ST |
480 | Sliding Window Median | Heap + Redundancy | 6 | HARD | O(nlogn)? | CPP |
|
493 | Reverse Pairs | Merge Sort | 5 | HARD | O(nlogn) | CPP |
|
494 | Target Sum | Dynamic Programming (Backpack) | 1 | MEDIUM | O(ns) | CS |
S |
502 | IPO | Greedy Strategy | 2 | HARD | O(nlogn) | CPP |
|
514 | Freedom Trail | Dynamic Programming | 3 | HARD | O(mn^2) | CPP |
|
518 | Coin Change II | Dynamic Programming | 1 | MEDIUM | O(nm) | CS |
|
543 | Diameter of Binary Tree | Simulation | 0 | EASY | O(n) | CPP |
|
547 | Number of Provinces | Breadth-first Search | 2 | MEDIUM | O(n^2) | CPP |
|
552 | Student Attendance Record II | Dynamic Programming | 2 | HARD | O(n) | CPP |
|
560 | Subarray Sum Equals K | Hashing + Prefix Sum | 2 | MEDIUM | O(n^2) | CS |
|
598 | Range Addition II | Simulation | 0 | EASY | CPP |
||
600 | Non-negative Integers without Consecutive Ones | Dynamic Programming | 3 | HARD | O(logn) | CPP |
|
629 | K Inverse Pairs Array | Dynamic Programming | 5 | HARD | O(nk) | CPP |
|
632 | Smallest Range Covering Elements From K Lists | Greedy Strategy (Heap) | 3 | HARD | O(nlogn) | CPP |
|
639 | Decode Ways II | Dynamic Programming | 2 | HARD | O(n) | CPP |
|
664 | Strange Printer | Dynamic Programming | 8 ★ | HARD | O(n^3) | CPP |
|
679 | 24 Game | Simulation | 2 | HARD | CPP |
||
685 | Redundant Connection II | Union-Find Algorithm | 3 | HARD | O(nlogn) | CPP |
|
699 | Falling Squares | Segment Tree + Discretization | 5 | HARD | O(nlogn) | CPP |
|
739 | Daily Temperature | Stack | 0 | MEDIUM | O(n) | CPP |
|
753 | Cracking the Safe | Eulerian Circuit (Hierholzer Algorithm) | 9 ★ | HARD | O(k^2n) | CPP |
|
765 | Couples Holding Hands | Union-find Algorithm | 5 | HARD | O(n^2) | CPP |
|
768 | Max Chunks to Make Sorted II | Greedy Strategy (Monotonic Stack) | 3 | HARD | O(n) | CPP |
|
773 | Sliding Puzzle | Breadth-first Search | 3 | HARD | / | CPP |
|
778 | Swim in Rising Water | Greedy Strategy(Heap) + Breadth-first Search | 3 | HARD | O(n^2logn) | CPP |
|
793 | Preimage Size of Factorial Zeroes Function | Primary Math + Binary Search | 6 | HARD | CPP |
||
801 | Minimum Swaps To Make Sequences Increasing | Dynamic Programming | 1 | HARD | O(n) | CPP |
|
805 | Split Array With Same Average | Divide And Conquer + Hash + Depth-first Search | 5 | HARD | O(n*2^n) | CPP |
|
827 | Making a Large Island | Breadth-first Search | 2 | HARD | O(n^2) | CPP |
|
828 | Counting Unique Characters of All Substrings | Simulation (Counting) | 4 | HARD | O(n) | CPP |
|
829 | Consecutive Numbers Sum | Primary Math | 2 | HARD | CPP |
||
834 | Sum of Distances In Tree | Dynamic Programming + Depth-first Search | 4 | HARD | O(n) | CPP |
|
847 | Shortest Path Visiting All Nodes | Breadth-first Search + Bit Mask | 6 | HARD | O(n^2*2^n) | CPP |
|
850 | Rectangle Area II (Acceptable Solution) | Simulation | 3 | HARD | O(n^3) | / | |
850F | Rectangle Area II (Optimal Solution) | Computational Geometry (Sweeping Line) + Segment Tree + Discretization (Hashing) | 7 ★ | HARD | O(nlogn) | CPP |
|
862 | Shortest Subarray with Sum at Least K | Dynamic Programming (Monotonic Queue + Binary Search) + Prefix Sum | 5 | HARD | O(nlogn) | CPP |
|
864 | Shortest Path to Get All Keys | Bit Mask + Breadth-first Search | 4 | HARD | O(nm2^k) | CPP |
|
871 | Minimum Number of Refueling Stops | Greedy Strategy (Heap) | 2 | HARD | O(nlogn) | CPP |
|
878 | Nth Magical Number | Math Theory + Binary Search | 7 ★ | HARD | CPP |
||
887 | Super Egg Drop | Induction + Dynamic Programming + Binary Search | 8 ★ | HARD | / | CPP |
|
891 | Sum of Subsequence Width | Primary Math + Sort | 2 | HARD | O(nlogn) | CPP |
|
895 | Max Frequency Stack | Heap | 1 | HARD | O(nlogn) | CPP |
|
902 | Numbers At Most N Given Digit Set | Simulation | 2 | HARD | O(logn) | CPP |
|
956 | Tallest Billboard | Dynamic Programming + Hash | N/A | HARD | O(ns^2) | CPP |
T |
968 | Binary Tree Cameras | Dynamic Programming | 4 | HARD | O(n) | CPP |
|
975 | Odd Even Jump | Dynamic Programming + Binary Search Tree | 4 | HARD | O(nlogn) | CPP |
|
996 | Number of Squareful Arrays | Bit Mask + Dynamic Programming | N/A | HARD | O(sqrt(d) n^2*2^n) | CPP |
T |
1012 | Numbers With Repeated Digits | Dynamic Programming | 5 | HARD | / | CPP |
|
1025 | Divisor Game | Induction / Gaming Theory | 3 | EASY | CPP |
||
1095 | Find in Mountain Array | Binary Search | 4 | HARD | O(logn) | CPP |
|
1106 | Parsing a Boolean Expression | Stack | 2 | HARD | O(n) | CPP |
|
1137 | N-th Tribonacci Number | Dynamic Programming | 0 | EASY | O(n) | CPP |
|
1210 | Minimum Moves to Reach Target with Rotations | Breadth-first Search | 2 | HARD | O(n^2) | CPP |
|
1220 | Count Vowels Permutation | Dynamic Programming | 0 | HARD | O(n) | CPP |
|
1223 | Dice Roll Simulation | Dynamic Programming | 2 | HARD | O(nm) | CPP |
|
1235 | Maximum Profit In Job Scheduling | Dynamic Programming + Discretization + Sort | 2 | HARD | O(nlogn) | CPP |
|
1250 | Check If It's a Good Array | Primary Math | 1 | HARD | O(nlogn) | CPP |
|
1261 | Find Elements in a Contaminated Binary Tree | Breadth-first Search | 0 | MEDIUM | O(n) | CS / TS |
|
1263 | Minimum Moves to Move a Box to Their Target Location | Breadth-first Search | 4 | HARD | O(n^4) | CPP |
|
1269 | Number of Ways to Stay in the Same Place After Some Steps | Dynamic Programming | 2 | HARD | O(n^2) | CPP |
|
1289 | Minimum Falling Path Sum II | Dynamic Programming | 1 | HARD | O(n^2) | CPP |
|
1298 | Maximum Candies You Can Get from Boxes | Topological Sort | 3 | HARD | O(n) | CPP |
|
1320 | Minimum Distance to Type a Word Using Two Fingers | Dynamic Programming | 1 | HARD | O(nk^2) | CPP |
|
1326 | Minimum Number of Taps to Open to Water a Garden | Greedy Strategy (Sort) | 4 | HARD | O(nlogn) | CPP |
|
1335 | Minimum Difficulty of a Job Schedule | Dynamic Programming | 1 | HARD | O(dn^2) | CPP |
|
1345 | Jump Game IV | Breadth-first Search | 3 | HARD | CPP |
||
1349 | Maximum Students Taking Exam | Bit Mask + Dynamic Programming | 3 | HARD | O(nm2^(2m)) | CPP |
|
1359 | Count All Valid Pickup and Delivery Options | Combinatorics | 0 | HARD | O(n) | CPP |
|
1377 | Frog Position After T Seconds | Depth-first Search | 1 | HARD | O(n) | CPP |
|
1392 | Longest Happy Prefix | Suffix Array (KMP) | 1 | HARD | O(n) | CPP |
|
1402 | Reducing Dishes | Dynamic Programming | 3 | HARD | O(n^2) | CPP |
|
1411 | Number of Ways to Paint Nx3 Grid | Dynamic Programming | 3 | HARD | O(n) | CPP |
|
1416 | Restore the Array | Dynamic Programming | 2 | HARD | O(nlogk) | CPP |
|
1420 | Build Array Where You Can Find The Maximum Exactly K Comparisons | Dynamic Programming + Prefix Sum + Scrolling Array | 5 | HARD | O(n^2m^2) | CPP |
|
1425 | Constrained Subsequence Sum | Dynamic Programming + Sliding Window | 3 | HARD | O(n) | CPP |
|
1434 | Number of Ways to Wear Different Hats to Each Other | Bit Mask + Dynamic Programming | 4 | HARD | O(nm*2^n) | CPP |
|
1444 | Number of Ways of Cutting a Pizza | Dynamic Programming + Prefix Sum | 4 | HARD | O(nmk(m+n)) | CPP |
|
1463 | Cherry Pickup II | Dynamic Programming | 5 | HARD | O(nm^2) | CPP |
|
1473 | Paint House III | Dynamic Programming | 4 | HARD | O(n^2m^2) | CPP |
|
1499 | Max Value of Equation | Greedy Strategy (Sliding Window) | 2 | HARD | O(n) | CPP |
|
1515 | Best Position for a Service Center | Simulated Annealing | 6 | HARD | CS |
L | |
1537 | Get the Maximum Score | Two Pointers | 3 | HARD | O(n+m) | CPP |
|
1547 | Minimum Cost to Cut a Stick | Dynamic Programming | 3 | HARD | O(m^3) | CPP |
|
1610 | Maximum Number of Visible Points | Computational Geometry + Sort | 4 | HARD | CPP |
||
1665 | Minimum Initial Energy to Finish Tasks | Greedy Strategy (Sort) + Simulation | 4 | HARD | O(nlogn) | CPP |
|
1671 | Minimum Number of Removals to Make Mountain Array | Dynamic Programming (LIS) + Binary Search | 3 | HARD | O(nlogn) | CPP |
|
1681 | Minimum Incompatibility | Dynamic Programming + Bit Mask + Hash | 4 | HARD | O(n2^n) | CPP |
|
1723 | Find Minimum Time to Finish All Jobs | Bit Mask + Dynamic Programming | 4 | HARD | O(k*3^n) | CPP |
|
1739 | Building Boxes | Binary Search | 6 | HARD | O(logn) | CPP |
|
1751 | Maximum Number of Events That Can Be Attended II | Dynamic Programming + Discretization (Hash + Sort) | 3 | HARD | O(nlogn+nk) | CPP |
|
1770 | Maximum Score from Performing Multiplication Operations | Dynamic Programming | 1 | HARD | O(m^2) | CPP |
|
1793 | Maximum Score of a Good Subarray | Two Pointers | 2 | HARD | O(n) | CPP |
|
1840 | Maximum Building Height | Stack + Sort + Math (Geometry) | 4 | HARD | O(nlogn) | CPP |
|
1851 | Minimum Interval to Include Each Query | Greedy Strategy (Heap+Sort) + Two Pointers | 4 | HARD | O(nlogn) | CPP |
|
1866 | Number of Ways to Rearrange Sticks With K Sticks Visible | Dynamic Programming + Combinatorics | 7 | HARD | O(nk) | CPP |
|
1884 | Egg Drop With 2 Eggs and N Floors | Dynamic Programming + Induction + Binary Search | 6 | MEDIUM | O(logn) | CPP |
|
1931 | Painting a Grid With Three Different Colors | Dynamic Programming | 2 | HARD | O(n*3^(2m)) | CPP |
|
1944 | Number of Visible People in a Queue | Monotonic Stack | 4 | HARD | CPP |
||
1969 | Minimum Non-Zero Product of the Array Elements | Fast Power Algorithm | 4 | MEDIUM | O(nlogn) | CS |
|
1976 | Number of Ways to Arrive at Destination | Dijkstra (Heap) + Topological Sort | 5 | MEDIUM | O(n^2logn) | CPP |
|
1994 | The Number of Good Subsets | Bit Mask + Dynamic Programming | 5 | HARD | O(m*2^m+logn) | CPP |
|
2097 | Valid Arrangement of Pairs | Eulerian Circuit (Hierholzer Algorithm) + Constant Reduction (TLE Avoidance) + Hash | 8 ★ | HARD | O(n^2) | CPP |
|
2147 | Number of Ways to Divide a Long Corridor | Simulation | 1 | HARD | O(n) | CPP |
|
2156 | Find Substring With Given Hash Value | Primary Math + Sliding Window (Rolling Hash) | 3 | HARD | O(n) | CPP |
|
2129 | Capitalize the Title | Simulation | 1 | EASY | O(n) | CS |
|
2218 | Maximum Value of K Coins From Piles | Dynamic Programming + Prefix Sum | 3 | HARD | O(nk)? | CPP |
|
2251 | Number of Flowers in Full Bloom | Two Pointers + Sort | 2 | HARD | O(nlogn) | CPP |
|
2258 | Escape the Spreading Fire | Breadth-first Search + Binary Search | 6 | HARD | O(nmlog(nm)) | CPP |
|
2262 | Total Appeal of a String | Simulation (Counting) | 4 | HARD | O(n) | CPP |
|
2312 | Selling Pieces of Wood | Dynamic Programming | 4 | HARD | O(mn(m+n)) | CPP |
|
2318 | Number of Distinct Roll Sequences | Dynamic Programming | 2 | HARD | O(n) | CPP |
|
2368 | Reachable Nodes With Restrictions | Breadth-first Search | 0 | MEDIUM | O(n) | CS |
|
2369 | Check if There is a Valid Partition For The Array | Dynamic Programming | 0 | MEDIUM | O(n) | CPP |
|
2386 | Find the K-Sum of an Array | Sort + Heap | 7 | HARD | O(nlogn+klogk) | CPP |
|
2407 | Longest Increasing Subsequence | Segment Tree + Dynamic Programming | 2 | HARD | O(nlogn) | CPP |
|
2426 | Number of Pairs Satisfying Inequality | Binary Indexed Tree | 2 | HARD | O(nlogn) | CPP |
|
2454 | Next Greater Element IV | Monotonic Stack | 5 | HARD | O(n) | CPP |
|
2509 | Cycle Length Queries in a Tree | Binary Operation | 4 | HARD | O(n) | CPP |
|
2549 | Count Distinct Numbers on Board | Simulation | -1 | EASY | O(1) | TS |
|
2569 | Handling Sum Queries After Update | Segment Tree | 5 | HARD | O(nlogn) | CPP |
|
2575 | Find the Divisibility Array of a String | Simulation | 0 | MEDIUM | O(n) | TS |
|
2580 | Count Ways to Group Overlapping Ranges | Simulation | 0 | MEDIUM | O(nlogn) | CPP |
|
2617 | Minimum Number of Visited Cells in a Grid | Heap + Breadth-first Search | 6 | HARD | O(nlogn) | CPP |
|
2642 | Design Graph With Shortest Path Calculator | Shortest Path | 2 | HARD | O(n^3logn) | CPP |
|
2671 | Frequency Tracker | Hash | 1 | MEDIUM | O(nm) | TS |
|
2681 | Power of Heroes | Sort | 3 | HARD | O(nlogn) | CPP |
|
2684 | Maximum Number of Moves in a Grid | Dynamic Programming | 0 | MEDIUM | O(mn) | CS |
|
2736 | Maximum Sum Queries | Sort + Discretization + Segment Tree + Binary Search (BST) | 6 | HARD | O(nlogn) | CPP |
|
2789 | Find the Minimum Possible Sum of a Beautiful Array | Greedy Strategy (Simulation) | 1 | MEDIUM | O(n) | CS |
|
2834 | Find the Minimum Possible Sum of a Beautiful Array | Greedy Strategy (Math) | 1 | MEDIUM | O(1) | CS |
|
2864 | Maximum Odd Binary Number | Greedy Strategy (Simulation) | -1 | EASY | O(n) | TS |
|
2908 | Minimum Sum of Mountain Triplets I | Simulation | -2 | EASY | O(n^2) | TS |
|
2909 | Minimum Sum of Mountain Triplets II | Monotonic Stack | 3 | MEDIUM | O(n) | CS |
|
2926 | Maximum Balanced Subsequence | Segment Tree + Dynamic Programming + Discretization | 3 | HARD | O(nlogn) | CPP |
|
2940 | Find Building Where Alice and Bob Can Meet | Binary Search + Monotonic Stack + Sort | 5 | HARD | O(nlogn) | CPP |
|
2952 | Minimum Number of Coins to be Added | Sort + Greedy Strategy | 4 | MEDIUM | O(nlogn) | CS |
|
3027 | Find the Number of Ways to Place People II | Simulation + Sort | 1 | HARD | O(n) | CPP |
|
LCR126 | Fibonacci Number | Dynamic Programming | 0 | EASY | O(n) | CPP |
|
LCR187 | Ice Breaking Game | Dynamic Programming (Joseph Ring) | 3 | EASY | O(n) | CPP |
Simulation
means the problem can be solved using Brute Force
algorithm (Do what you are asked to do)
ID | Problem | Annotated Difficulty | Status |
---|---|---|---|
Nothing Now |
ID | Problem | Solution Adopted | Time/Space Complexity | Optimal Solution | Time/Space Complexity |
---|---|---|---|---|---|
15 | 3 Sum | Hash | O(n^3)* | Two Pointers | O(n^2) |
31 | Next Permutation | Selection Sort | O(n^2) | Sort (Reverse) | O(n) |
43 | Multiply String | Simulation | O(n^2) | Fast Fourier Transform | O(nlogn) |
70 | Climbing Stairs | Dynamic Programming | O(n) | Dynamic Programming + Matrix Fast Power Algorithm | O(logn) |
74 | Search A 2D Matrix | Simulation | O(n+m) | Binary Search | O(logn+logm) |
81 | Search In Rotated Sorted Array II | Simulation | O(n) | Binary Search | O(logn) |
143 | Reorder List | Simulation | S(n) | Linked List Reverse | S(1) |
214 | Shortest Palindrome | Rabin-Karp | O(n^2)* | Manacher | O(n) |
LCR126 | Fibonacci Number | Dynamic Programming | O(n) | Dynamic Programming + Matrix Fast Power Algorithm | O(logn) |
*. Worst case of hash function
T
: An accepted but time-consuming algorithmS
: An accepted but space-consuming algorithmL
: This is a legacy (old) submissionP
: Follow-up challenge incomplete
It's RIDICULOUS to see the mismatched difficulty annotated in the problem set (e.g. HARD NQueens
)
Perceived difficulty is a subjective rating to a problem. The criteria might be subject to the personal experience.
Rank | -2 | -1 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
Difficulty | TU- | TU | TU+ | EZ- | EZ | EZ+ | MD- | MD | MD+ | HD- | HD | HD+ | IN- | IN | IN+ |
-
TU
: Tutorial -
EZ
: Easy -
MD
: Medium -
HD
: Hard -
IN
: Inferno