In this repo, I do not list those common and easy problems.
One problem may be classified as multiple types.
(PS. 这个readme是用来骗提交的)
# | title | Name | solved | # Week |
---|---|---|---|---|
509 | Fibonacci Number | Recursive | Yes | Week1 |
70 | Climibing stages | DP | Yes | Week1 |
62 | Unique Paths | DP | Yes | Week1 |
63 | Unique Paths II | DP | Yes | Week1 |
120 | Triangle | DP | Yes | Week1 |
279 | Perfect Squares | DP | Yes | Week1 |
375 | Guess Number Higher or Lower II | DP | ! | Week2 |
312 | Burst Balloons | DP | !(hard) | Week2 |
300 | longest increasing subsequence | Binary Search O(nlong) | ! | Week2 |
673 | Number of Longest Increasing Subsequence | DP | two DPs | Week2 |
322 | Coin Change | DP | special cases | Week2 |
# | title | Level | solved |
---|---|---|---|
1588 | Sum of All Odd Length Subarrays | easy | Array |
1589 | Maximum Sum Obtained of Any Permutation | medium | Array & greddy |
1590 | Make Sum Divisible by P | medium | Hashtable |
# | title | Level | solved |
---|---|---|---|
1572 | Matrix Diagonal Sum | easy | Array |
1573 | Number of Ways to Split a String | medium | Greedy |
1574 | Shortest Subarray to be Removed to Make Array Sorted | medium | Monotic Array |
1575 | Count All Possible Routes | hard | DP |
# | title | Level | solved |
---|---|---|---|
1556 | Thousand Separator | easy | String |
1557 | Minimum Number of Vertices to Reach All Nodes | medium | Graph |
1558 | Minimum Numbers of Function Calls to Make Target Array | medium | Math |
1559 | Detect Cycles in 2D Grid | hard | BFS |
# | title | Level | solved |
---|---|---|---|
1539 | Kth Missing Positive Number | easy | Array |
1540 | Can Convert String in K Moves | medium | Math |
1541 | Minimum Insertions to Balance a Parentheses String | medium | Stack |
1542 | Find Longest Awesome Substring | Hard | Bit Mask |
# | title | Level | solved |
---|---|---|---|
1523 | Count Odd Numbers in an Interval Range | easy | Math |
1524 | Number of Sub-arrays With Odd Sum | medium | DP |
1525 | Number of Good Ways to Split a String | Hashmap | |
1526 | Minimum Number of Increments on Subarrays to Form a Target Array | hard | Difference array |
# | title | Level | solved |
---|---|---|---|
1507 | Reformat Date | easy | String |
1508 | Range Sum of Sorted Subarray Sums | medium | Heap |
1509 | Minimum Difference Between Largest and Smallest Value in Three Moves | medium | Array |
1510 | Stone Game IV | medium | DP |
# | title | Level | solved |
---|---|---|---|
1491 | Average Salary Excluding the Minimum and Maximum Salary | easy | Array |
1492 | The kth Factor of n | medium | Array |
1493 | Longest Subarray of 1's After Deleting One Element | meidum | Sliding Window(zero count) |
1494 | Parallel Courses II | hard | Graph(inverse thinking, start from the end) |
# | title | Level | solved |
---|---|---|---|
1475 | Final Prices With a Special Discount in a Shop | easy | Array |
1476 | Subrectangle Queries | meidum | Array |
1477 | Find Two Non-overlapping Sub-arrays Each With Target Sum | medium | Prefix sum or Sliding window |
1478 | Allocate Mailboxes | hard | Build cost array(math problem), build dp array |
# | title | Level | solved |
---|---|---|---|
1460 | Make Two Arrays Equal by Reversing Sub-arrays | easy | Array |
1461 | Check If a String Contains All Binary Codes of Size K | medium | String |
1462 | Course Schedule IV | medium | DFS |
1463 | Cherry Pickup II | hard | (bottom-top)DP+DFS |
# | title | Level | solved |
---|---|---|---|
1446 | Consecutive Characters | easy | Sliding Window |
1447 | Simplified Fractions | medium | String |
1448 | Count Good Nodes in Binary Tree | medium | Top-down dfs |
1449 | Form Largest Integer With Digits That Add up to Target | hard | DP |
# | title | Level | solved |
---|---|---|---|
1431 | Kids With the Greatest Number of Candies | easy | Array |
1432 | Max Difference You Can Get From Changing an Integer | medium | String |
1433 | Check If a String Can Break Another String | medium | String |
1434 | Number of Ways to Wear Different Hats to Each Other | hard | DP |
# | title | Level | solved |
---|---|---|---|
1413 | Minimum Value to Get Positive Step by Step Sum | easy | Prefix Sum |
1414 | Find the Minimum Number of Fibonacci Numbers Whose Sum Is K | medium | greedy |
1415 | The k-th Lexicographical String of All Happy Strings of Length n | medium | recursive |
1416 | Restore The Array | hard | DP |
# | title | Level | solved |
---|---|---|---|
1399 | Count Largest Group | easy | Yes(sort and count) |
1400 | Construct K Palindrome Strings | medium | Yes(Math, count odd-occurence numbers) |
1401 | Circle and Rectangle Overlapping | medium | Yes(Math, find closest points on edge) |
1402 | Reducing Dishes | hard | Yes(Sort) |
# | title | Level | solved |
---|---|---|---|
1385 | Find the Distance Value Between Two Arrays | easy | Array |
1386 | Cinema Seat Allocation | medium | Array |
1387 | Sort Integers by The Power Value | medium | Sort |
1388 | Pizza With 3n Slices | hard | didn't solve it!!! |
# | title | Level | solved |
---|---|---|---|
1582 | Special Positions in a Binary Matrix | easy | Array |
1583 | Count Unhappy Friends | medium | Dict |
1584 | Min Cost to Connect All Points | medium | Greedy |
1585 | Check If String Is Transformable With Substring Sort Operations | hard | Deque |
# | title | Level | solved |
---|---|---|---|
1576 | Replace All 's to Avoid Consecutive Repeating Characters | easy | Set |
1577 | Number of Ways Where Square of Number Is Equal to Product of Two Numbers | medium | Dict |
1578 | Minimum Deletion Cost to Avoid Repeating Letters | medium | Array |
1579 | Remove Max Number of Edges to Keep Graph Fully Traversable | hard | Union find |
# | title | Level | solved |
---|---|---|---|
1566 | Detect Pattern of Length M Repeated K or More Times | easy | Array |
1567 | Maximum Length of Subarray With Positive Product | medium | Array(use two auxiliary arrays: pos and num) |
1568 | Minimum Number of Days to Disconnect Island | medium | DFS(Tricky: at most 2 days) |
1569 | Number of Ways to Reorder Array to Get Same BST | hard | Recursive(use combination) |
# | title | Level | solved |
---|---|---|---|
1560 | Most Visited Sector in a Circular Track | easy | Array |
1561 | Maximum Number of Coins You Can Get | medium | Greedy |
1562 | Find Latest Group of Size M | meidum | Union find |
1563 | Stone Game V | hard | DP |
# | title | Level | solved |
---|---|---|---|
1550 | Three Consecutive Odds | easy | Array |
1551 | Minimum Operations to Make Array Equal | medium | Math |
1552 | Magnetic Force Between Two Balls | medium | Binary Search |
1553 | Minimum Number of Days to Eat N Oranges | hard | BFS or DP |
# | title | Level | solved |
---|---|---|---|
1544 | Make The String Great | easy | String |
1545 | Find Kth Bit in Nth Binary String | medium | Recursive based on Symmetry |
1546 | Maximum Number of Non-Overlapping Subarrays With Sum Equals Target | medium | Predix Sum&Hashmap |
1547 | Minimum Cost to Cut a Stick | hard | DP(same as 312 Burst Bolloons. Interval DP) |
# | title | Level | solved |
---|---|---|---|
1534 | Count Good Triplets | easy | BF |
1535 | Find the Winner of an Array Game | medium | Array |
1536 | Minimum Swaps to Arrange a Binary Grid | medium | Greedy |
1537 | Get the Maximum Score | hard | Two pointers |
# | title | Level | solved |
---|---|---|---|
1528 | Shuffle String | easy | String |
1529 | Bulb Switcher IV | medium | Array |
1530 | Number of Good Leaf Nodes Pairs | medium | DFS |
# | title | Level | solved |
---|---|---|---|
1518 | Water Bottles | easy | Math |
1519 | Number of Nodes in the Sub-Tree With the Same Label | medium | DFS |
1520 | Maximum Number of Non-Overlapping Substrings | medium | Minmax |
1521 | Find a Value of a Mysterious Function Closest to Target | hard | Set |
# | title | Level | solved |
---|---|---|---|
1512 | Number of Good Pairs | easy | Array |
1513 | Number of Substrings With Only 1s | medium | Sliding Window |
1514 | Path with Maximum Probability | medium | BFS |
1515 | Best Position for a Service Centre | hard | Binary Search |
# | title | Level | solved |
---|---|---|---|
1502 | Can Make Arithmetic Progression From Sequence | easy | Array |
1503 | Last Moment Before All Ants Fall Out of a Plank | medium | MAXMIN |
1504 | Count Submatrices With All Ones | medium | DP |
# | title | Level | solved |
---|---|---|---|
1496 | Path Crossing | easy | Hashmap |
1497 | Check If Array Pairs Are Divisible by k | medium | Array(similar to target sum) |
1498 | Number of Subsequences That Satisfy the Given Sum Condition | medium | Array(sort then two sum) |
1499 | Max Value of Equation | hard | Convert to yi-xi+yj+xj, given j find max of (yi-xi), MAX heap |
# | title | Level | solved |
---|---|---|---|
1486 | XOR Operation in an Array | easy | Array |
1487 | Making File Names Unique | meidum | Hashmap |
1488 | Avoid Flood in The City | medium | Heap and Hashmap |
# | title | Level | solved |
---|---|---|---|
1480 | Running Sum of 1d Array | easy | Array |
1481 | Least Number of Unique Integers after K Removals | medium | Heap |
1482 | Minimum Number of Days to Make m Bouquets | medium | Binary Search |
1483 | Kth Ancestor of a Tree Node | Hard |
# | title | Level | solved |
---|---|---|---|
1470 | Shuffle the Array | easy | Array |
1471 | The k Strongest Values in an Array | medium | Array |
1472 | Design Browser History | medium | Array |
1473 | Paint House III | hard | Top-down dfs+DP |
# | title | Level | solved |
---|---|---|---|
1464 | Maximum Product of Two Elements in an Array | easy | Array |
1465 | Maximum Area of a Piece of Cake After Horizontal and Vertical Cuts | medium | Array |
1466 | Reorder Routes to Make All Paths Lead to the City Zero | medium | DFS, contraints show that there will be not loops in the graph |
1467 | Probability of a Two Boxes Having The Same Number of Distinct Balls | hard | Did not solve! |
# | title | Level | solved |
---|---|---|---|
1455 | Check If a Word Occurs As a Prefix of Any Word in a Sentence | easy | String |
1456 | Maximum Number of Vowels in a Substring of Given Length | medium | Sliding window |
1457 | Pseudo-Palindromic Paths in a Binary Tree | medium | Tree, check palindrome and run dfs |
1458 | Max Dot Product of Two Subsequences | hard | Same as longest common subsequence(1143) |
# | title | Level | solved |
---|---|---|---|
1450 | Number of Students Doing Homework at a Given Time | easy | Array |
1451 | Rearrange Words in a Sentence | medium | Array |
1452 | People Whose List of Favorite Companies Is Not a Subset of Another List | medium | Set |
1453 | Maximum Number of Darts Inside of a Circular Dartboard | hard | Math, O(N^3) find pairs of points and define a circle |
# | title | Level | solved |
---|---|---|---|
1441 | Build an Array With Stack Operations | easy | Array |
1442 | Count Triplets That Can Form Two Arrays of Equal XOR | medium | Prefix Sum, Assume a == b, thus a ^ a = b ^ a, thus 0 = b ^ a |
1443 | Minimum Time to Collect All Apples in a Tree | medium | Bottom-up DFS |
# | title | Level | solved |
---|---|---|---|
1436 | Destination City | easy | Array |
1437 | Check If All 1's Are at Least Length K Places Away | medium | Array |
1438 | Longest Continuous Subarray With Absolute Diff Less Than or Equal to Limit | medium | Heap |
1439 | Find the Kth Smallest Sum of a Matrix With Sorted Rows | hard |
# | title | Level | solved |
---|---|---|---|
1422 | Maximum Score After Splitting a String | easy | Use counter |
1423 | Maximum Points You Can Obtain from Cards | medium | Use sliding window to find the sub-array with max sum |
1424 | Diagonal Traverse II | medium | Indexes on the diagonal have the same SUM |
# | title | Level | solved |
---|---|---|---|
1417 | Reformat The String | easy | String |
1418 | Display Table of Food Orders in a Restaurant | medium | dictionary |
1419 | Minimum Number of Frogs Croaking | medium | the solution is very tricky |
1420 | Build Array Where You Can Find The Maximum Exactly K Comparisons | hard | 3D dp, not easy to come up with |
# | title | Level | solved |
---|---|---|---|
1408 | String Matching in an Array | easy | Array |
1409 | Queries on a Permutation With Key | medium | Array |
1410 | HTML Entity Parser | medium | String |
1411 | Number of Ways to Paint N × 3 Grid | hard | DP |
# | title | Level | solved |
---|---|---|---|
1403 | Minimum Subsequence in Non-Increasing Order | easy | Sort |
1404 | Number of Steps to Reduce a Number in Binary Representation to One | easy | Math |
1405 | Longest Happy String | medium | Greedy |
1406 | Stone Game III | hard | DP |
# | title | Level | solved |
---|---|---|---|
1394 | Find Lucky Integer in an Array | easy | Yes(Math) |
1395 | Count Number of Teams | medium | Yes(backtrack) |
1396 | Design Underground System | medium | Yes(collection.dictionary) |
1397 | Find All Good Strings | hard | No(several test cases passed) |
# | title | Level | solved |
---|---|---|---|
1389 | Create Target Array in the Given Order | easy | Yes(sort) |
1390 | Four Divisors | medium | Yes(Math) |
1391 | Check if There is a Valid Path in a Grid | medium | Yes(DFS, BFS) |
1392 | Longest Happy Prefix | Hard | Yes(sliding widnow) |
# | title | Level | solved |
---|---|---|---|
1380 | Lucky Numbers in a Matrix | easy | Yes |
1381 | Design a Stack With Increment Operation | Medium | Stack |
1382 | Balance a Binary Search Tree | Medium | contruct a Binary Search Tree |
1383 | Maximum Performance of a Team | hard | Priority Queue(close to 857) |
# | title | note |
---|---|---|
665 | Non-decreasing Array | detect first decrease pair, analyze two possible cases |
1002 | Find Common Characters | One pass(though easy question, pretty tricky) |
1200 | Minimum Absolute Difference | Sort + hashmap |
867 | Transpose Matrix | A[i][j]==new_A[j][i] |
1260 | Shift 2D Grid | Array |
888 | Fair Candy Swap | Set, find target value in another set |
1089 | Duplicate Zeros | Array |
896 | Monotonic Array | Compare adjacent elements |
122 | Best Time to Buy and Sell Stock II | Always buy ant valley and sell at next peak, (good graph explaination)[https://leetcode.com/problems/best-time-to-buy-and-sell-stock-ii/discuss/208241/Explanation-for-the-dummy-like-me.] |
1013 | Partition Array Into Three Parts With Equal Sum | From left to right, find the first subset with target sum, then the second... |
121 | Best Time to Buy and Sell Stock | Typical sliding window technique to solve this problem |
746 | Min Cost Climbing Stairs | Top is confusing, make the dp array length -> length(cost)+1 |
830 | Positions of Large Groups | One pass |
1232 | Check If It Is a Straight Line | Use on point and compute the slope with the rest |
1128 | Number of Equivalent Domino Pairs | Hashtable, note: list type is not hashable, convert to string |
1010 | Pairs of Songs With Total Durations Divisible by 60 | 2 Sum question by doing mod operation on the given array good question |
1018 | Binary Prefix Divisible By 5 | Bit manipulation |
674 | Longest Continuous Increasing Subsequence | One pas, find start and end |
724 | Find Pivot Index | Typical prefix sum |
849 | Maximize Distance to Closest Person | find left 1 and right 1, between these two are all one's |
1346 | Check If N and Its Double Exist | Similar to target sum(2 sum) |
941 | Valid Mountain Array | Solution is easy but many conditions need to be satisfied |
581 | Shortest Unsorted Continuous Subarray | Sort + two indexes |
# | title | solved |
---|---|---|
7 | Reverse Integer | Yes |
165 | Comapre Version Numbers | Yes |
66 | Plus one | Yes |
258 | Add Digits | Yes |
67 | Add Binary | Yes |
69 | Sqrt(x) | Yes |
367 | Valid Perfect Square | Yes(bianry search) |
397 | Integer Replacement | Yes |
204 | Count Primes | Redo(time exceed) |
1 | Two Sum | Yes |
15 | Three Sum | Yes |
231 | Power of Two | Yes |
# | title | solved |
---|---|---|
454 | 4Sum II | Get sum count in A,B |
846 | Hand of Straights | Two maps: Order dict and need map(for storing the next needed number) |
# | title | note |
---|---|---|
61 | Rotate List | Two solutions:1. iterate k times or use two pointers |
457 | Circular Array Loop | Mark visited elements using numbers |
632 | Smallest Range Covering Elements from K Lists | 1. pointers+heap 2. sliding window |
828 | Count Unique Characters of All Substrings of a Given String | Find the last two occurence indexes for each letter |
76 | Minimum Window Substring | Sliding window, tricks: use two additional variables: found and target |
# | title | solved |
---|---|---|
98 | Validate Binary Search Tree | 1. Recursive 2. inoder traverse |
701 | Insert into a Binary Search Tree | 1. inorder then build tree 2. recursive(we can always put the new val in leaf node) |
99 | Recover Binary Search Tree | Inorder to find the swapped elements |
# | title | solved |
---|---|---|
959 | Regions Cut By Slashes | This union find solution does not apply path compression when doing the union operation |
684 | Redundant Connection | Each time before union, check if two vertices are in the same cluster using find |
547 | Friend Circles | A simple solution using Union Find |
1202 | Smallest String With Swaps | Convert to graph, then union, then sort |
990 | Satisfiability of Equality Equations | First union all the '==' equations, then find all '!=' equations |
765 | Couples Holding Hands | Consider each couple as a node, find all the connected clusters, apply permutation theorem(N//2- (# of clusters)) |
128 | Longest Consecutive Sequence | Using set to keep track of the visited numbers, use union to connect all consecutive elements |
839 | Similar String Groups | Union find is right but Python version is LTE |
# | title | solved |
---|---|---|
310 | Minimum Height Trees | start from leaves, delete and find new leaves until n <= 2 |
399 | Evaluate Division | one test case is wrong??? |
149 | Max Points on a Line | hard, brute search |
207 | Course Schedule | DFS + extra array for checking if cur node will form a loop |
210 | Course Schedule II | BFS + queue |
1377 | Frog Position After T Seconds | BFS + queue, remove neighbors that have been visited |
133 | Clone Graph | Queue + hashmap |
138 | Copy List with Random Pointer | Similar to 133, queue + hashmap |
827 | Making A Large Island | DFS replaces island with unique index |
1162 | As Far from Land as Possible | BFS updates 0 to 1 till all become 1s |
# | title | solved |
---|---|---|
146 | LRU Cache | Use ordered dict |
284 | Peeking Iterator | Use a variable to store peek value |
341 | Flatten Nested List Iterator | Use stack to break down nested list |
352 | Data Stream as Disjoint Intervals | 1. Binary search 2. Heap |
303 | Range Sum Query - Immutable | Prefix sum |
# | title | solved |
---|---|---|
304 | Range Sum Query 2D - Immutable | dp[i][j] stores the element sum from arr[i][j] to arr[r-1][c-1] |
1124 | Longest Well-Performing Interval | Convert to -1/+1 representation and search for subarry with positive sum |
# | title | solved |
---|---|---|
416 | Partition Equal Subset Sum | DP or set sum |
392 | Is Subsequence | Iterate T and compare each value with s[0] |
1277 | Count Square Submatrices with All Ones | Find the number of submatrices ending at index i,j |
338 | Counting Bits | dp[i]=dp[i>>1]+i%2 |
1130 | Minimum Cost Tree From Leaf Values | Greedy, always find the smallest one and its neighbor |
931 | Minimum Falling Path Sum | Same as seam carving algorithm |
1143 | Longest Common Subsequence | 2D DP |
1105 | Filling Bookcase Shelves | Unusual DP problem, current optimal solution relies on several previous states |
1027 | Longest Arithmetic Sequence | Use dictionary |
646 | Maximum Length of Pair Chain | O(N^2) dp solution, O(nlogn)+O(n) Greedy |
343 | Integer Break | find as many 3 as possible |
1155 | Number of Dice Rolls With Target Sum | dp_{ij} means i dice can get sum j |
813 | Largest Sum of Averages | dp_{ki} means by dividing first i numbers into k groups, the max sum we can get. O(kn^2) |
1024 | Video Stitching | dp_{ij} -> min clips to form i-j |
650 | 2 Keys Keyboard | My solution is to find all the factors given an N, then we can repeat the copy operation |
740 | Delete and Earn | Similar to house robber but need to do some conversion |
688 | Knight Probability in Chessboard | 3D DP |
1039 | Minimum Score Triangulation of Polygon | 2D DP, DP_{ij} means from i to j, the min triangle sum we can get |
873 | Length of Longest Fibonacci Subsequence | dp[i][j]: max len of seq ending with A[i],A[j], dp[k][i]+1 = dp[i][j] |
486 | Predict the Winner | Same as 877(Stone Game) |
1139 | Largest 1-Bordered Square | Create auxillary horizontal and vertical arrays |
659 | Split Array into Consecutive Subsequences | Maintain two hashmap for keeping track of the number frequence and next nums |
# | title | solved |
---|---|---|
42 | Trapping Rain Water | Yes |
139 | Work Break | Yes |
518 | Coin Change | Yes |
64 | Minimum Path Sum | Yes |
72 | Edit Distance | Yes |
221 | Maximal Square | Yes |
198 | House Robber | Yes |
213 | House Robber 2 | Yes |
337 | House Robber 3 | Yes |
85 | Maximal Rectangle | No |
91 | Decode Ways | Yes |
494 | Target Sum | Yes(2 solutions: dp and collections) |
877 | Stone Game | 2D DP, DP[i][j]: more stones one can get than another |
53 | Maximum Subarray | dp[i] means max subarray ending at index i |
576 | Out of Boundary Paths | 3D DP |
664 | Strange Printer | DP with memory |
# | title | solved |
---|---|---|
278 | Fisrt Bad Version | Yes |
35 | Search Insert Position | Yes |
33 | Search in Rotated Sorted Array | Yes(smallest index is tricky!) |
81 | Search in Rotated Sorted Array II(duplicate numbers) | Yes(search smallest index in O(logn) time!) |
153 | Find Minimum in Rotated Sorted Array | Yes |
154 | Find Minimum in Rotated Sorted Array II | Yes |
374 | Guess Number Higher or Lower | Yes |
34 | Find First and Last Position of Element in Sorted Array | Yes(find most left and most right index) |
354 | Russian Doll Envelopes | Yes(reduce to one dimension, then apply LLS) |
1283 | Find the Smallest Divisor Given a Threshold | Normal bianry search |
875 | Koko Eating Bananas | Same as 1283 |
1011 | Capacity To Ship Packages Within D Days | O(nlogn), left bound is max(A) and right bound is sum(A) |
1292 | Maximum Side Length of a Square with Sum Less than or Equal to Threshold | Array presum + binary search for side length |
1300 | Sum of Mutated Array Closest to Target | Careful about the left and right index, left=mid, right=mid |
668 | Kth Smallest Number in Multiplication Table | Find number counts in each row |
1201 | Ugly Number III | Union and intersection, basic math logic |
410 | Split Array Largest Sum | Find satisfying splits |
315 | Count of Smaller Numbers After Self | Bisect module used |
1235 | Maximum Profit in Job Scheduling | Bisect to find the inserted time slot |
1157 | Online Majority Element In Subarray | Store indexes in increasing order and use bisect find left and right inserted indexes, then apply early stop |
1095 | Find in Mountain Array | Binary search finds mountain index and binary search finds target |
719 | Find K-th Smallest Pair Distance | Binary search distance |
878 | Nth Magical Number | Least common multiplier |
# | title | solved |
---|---|---|
48 | Rotate Image | Yes |
54 | Spiral Matrix | Yes |
59 | Sipral Matrix 2 | No |
329 | Longest Increasing Path in a Matrix | Yes |
378 | Kth Smallest Element in a Sorted Matrix | Yes |
74 | Search a 2D Matrix | Yes |
240 | Search a 2D Matrix II | Yes |
# | title | solved |
---|---|---|
1004 | Max Consecutive Ones III | Yes(left and right index) |
209 | Minimum Size Subarray Sum | Yes(left right index), similar to 1004 |
904 | Fruit Into Baskets | Yes(maintain a hashmap for count) |
992 | Subarrays with K Different Integers | hard Yes(convert to AtMost problem) |
930 | Binary Subarrays With Sum | Yes(two ways: AtMost and HashMap) |
1234 | Replace the Substring for Balanced String | Yes(left > right, the return 0) |
1248 | Count Number of Nice Subarrays | 1. AtMost strategy 2. count |
1358 | Number of Substrings Containing All Three Characters | count # of letter on the left |
3 | Longest Substring Without Repeating Characters | find the longest subarray end at right |
567 | Permutation in String | backtrack(TLE), use COUNT |
424 | Longest Repeating Character Replacement | left and right index + count |
1208 | Get Equal Substrings Within Budget | left+right index, record cur maxCount value |
5 | Longest Palindromic Substring | start from center, left-=1 rigth += 1 |
647 | Palindromic Substrings | Close to problem 5, center expansion |
927 | Three Equal Parts | Starting from end, find a potential matching bianry reprsentation |
# | title | solved |
---|---|---|
307 | Range Sum Query - Mutable | Build Tree-> Update Tree-> Query Sum(all recursively) |
# | title | solved |
---|---|---|
88 | Merge Sorted Array | Yes |
922 | Sort Array By Parity II | tow pointers(tricky) |
1122 | Relative Sort Array | Yes |
976 | Largest Perimeter Triangle | Yes(Try biggest) |
23 | Merge k Sorted Lists | hard |
# | title | note |
---|---|---|
1376 | Time Needed to Inform All Employees | time=max(manager's employees)+informTime(manager) |
1319 | Number of Operations to Make Network Connected | DFS finds connected graphs(all the nodes reachable) |
1145 | Binary Tree Coloring Game | Find connected nodes and run dfs on each node to find the total count |
199 | Binary Tree Right Side View | level order traverse + DFS |
105 | Construct Binary Tree from Preorder and Inorder Traversal | DFS solve left and right sub-tree |
721 | Accounts Merge | DFS or Union Find |
934 | Shortest Bridge | DFS+BFS, DFS for island deetction and BFS for searching shortest path |
988 | Smallest String Starting From Leaf | leaf is a node where left and right are both None |
1028 | Recover a Tree From Preorder Traversal | Good problem |
332 | Reconstruct Itinerary | REDO |
109 | Convert Sorted List to Binary Search Tree | Find mid point value as new root |
114 | Flatten Binary Tree to Linked List | Restore preorder of the tree, then build new tree |
980 | Unique Paths III | DFS+memo |
1192 | Critical Connections in a Network | Good question(Tarjan algorithm), REDO |
897 | Increasing Order Search Tree | Inorder traverse to get all the nodes |
979 | Distribute Coins in Binary Tree | Post-order traverse, dfs(node) returns how many coins should go from(to) node.video explain |
785 | Is Graph Bipartite | DFS or BFS+dictionary, BFS is easier to understand |
399 | Evaluate Division | Tricky, build graph and run dfs or bfs |
# | title | note |
---|---|---|
116 | Populating Next Right Pointers in Each Node | Level order traverse |
117 | Populating Next Right Pointers in Each Node II | Same as 116 |
864 | Shortest Path to Get All Keys | Use 3-elements tuple to keep track of seen blocks |
1284 | Minimum Number of Flips to Convert Binary Matrix to Zero Matrix | Convert matrix to bin representation and BFS finds all the possible states |
847 | Shortest Path Visiting All Nodes | Use bit to keep track of visited nodes in seen(set) |
# | title | solved |
---|---|---|
200 | Number of island | Yes |
130 | surrounded regions | Yes |
127 | Word ladder | Yes |
397 | Integer Replacement | Yes |
417 | Pacific Atlantic Water Flow | Yes |
733 | Flood Fill | Yes |
778 | Swim in Rising Water | Yes |
433 | Minimum Genetic Mutation | Yes (close to 127) |
909 | Snakes and Ladders | Yes |
1025 | Divisor Game | Yes |
464 | Can I Win | Yes(solve sub-problem) |
110 | Balanced Bianry Tree | Yes(DFS) |
1315 | Sum of Nodes with Even-Valued Grandparent | Yes(loof for grands from current node) |
104 | Maximum Depth of Binary Tree | Yes |
841 | Keys and Rooms | Yes |
695 | Max Area of Island | Yes(dfs is tricky, set visited cells to 0's) |
1254 | Number of Closed Islands | Yes(cells can be reached by edge cells will be set to 1's(waster)) |
1034 | Coloring A Boarder | Yes(check four directionally connected cells) redo!!! |
872 | Leaf-Similar Trees | Yes |
559 | Maximum Depth of N-ary Tree | Yes |
547 | Friend Circle | Yes(DFS+memo) |
1020 | Number of Enclaves | Yes(close to 695) |
802 | Find Eventual Safe States | Yes(good dfs problem, help to know the dfs order) |
108 | Convert Sorted Array to Binary Search Tree | Yes |
994 | Rotting Oranges | Yes(should change from 'easy' to 'medium') |
513 | Find Bottom Left Tree Value | Yes(level order search) |
515 | Find Largest Value in Each Tree Row | Yes(close to 513, level order search) |
752 | Open the Lock | Yes(BFS, to improve runtime, use deque) |
542 | 01 Matrix | Yes(close to 752) |
1091 | Shortest Path in Binary Matrix | Yes(template for solving shortest path problem) |
1306 | Jump Game III | Queue |
# | title | solved |
---|---|---|
155 | Min Stack | Yes |
232 | Implementing Queue using Stack | Yes |
225 | Imppementing Stack using Queue | Yes |
150 | Evaluate Reverse Polish Notation | Yes |
394 | Decode String | Yes |
224 | Basic Calculator | Yes |
1019 | Next Greater Node In Linked List | good question, REDO |
739 | Daily Temperatures | Similar to 1019 |
901 | Online Stock Span | stack stores (val, res) |
# | title | solved |
---|---|---|
215 | Kth Largetst element in an Array | Yes |
347 | TopK frequent element | Yes |
20 | Valid Parentheses | a valid case results in an empty queue |
862 | Shortest Subarray with Sum at Least K | Keep increasing prefix sum |
1425 | Constrained Subset Sum | Keep a decreasing queue |
743 | Network Delay Time | BFS + deque |
239 | Sliding Window Maximum | Typical monotonic queue problem |
# | title | solved |
---|---|---|
78 | Subsets | Yes |
90 | No Duplicate Subset | Yes |
77 | Combination | Yes |
39 | Combination Sum | Yes |
40 | Combination Sum 2 | Yes |
216 | Combination Sum 3 | Yes |
377 | Combination Sum 4 | Yes |
46 | Permutation | Yes |
47 | Permutation 2 | Yes |
17 | Letter Combinations of a Phone Number | Yes |
357 | Count Numbers with Unique Digits | Yes(but very slow, faster than 5%, check bt template) |
131 | Palindrome Partitioning | Yes(can use template, note: path(reference) vs path[:](value)) |
22 | Generate Parentheses | Yes(very slow, better solution: DFS, DP) |
1219 | Path with Maximum Gold | Backtrack + BFS, good practice(template) |
1079 | Letter Tile Possibilities | follow template |
1239 | Maximum Length of a Concatenated String with Unique Characters | need to improve run time |
784 | Letter Case Permutation | two cases in backtrack: lower case and upper case |
491 | Increasing Subsequences | backtracking |
# | title | solved |
---|---|---|
31 | Next Permutation | Yes |
60 | Permutation Sequence | Yes |
159 | Longest substring with at most two distinct characters | 159 |
8 | String to Integer (atoi) | If-else practice |
869 | Reordered Power of 2 | Find all the power of 2 numbers first |
# | title | solved |
---|---|---|
144 | Pre Order Tree | Yes |
94 | In Order Tree | Yes |
145 | Post Order Tree | Yes |
102 | Level order Tree | Yes |
100 | Same Tree | Yes |
101 | Symmetric Tree | Yes |
226 | Invert Tree | Yes |
257 | binary tree path | Yes |
112 | binary tree sum | Yes |
113 | binary tree sum2 | Yes |
129 | Sum root to leaves | Yes |
111 | Minimum depth of a tree | Yes |
1302 | Deepest Leaves Sum | Yes(traverse each level) |
1110 | Delete Nodes And Return Forest | DFS is the key, remove node + set children to None |
107 | Binary Tree Level Order Traversal II | BFS for level traverse |
530 | Minimum Absolute Difference in BST | Inorder traverse ensures that we get a sorted result from a BST |
437 | Path Sum III | Two ways: 1. run dfs on each node 2. hashmap storing prefix sum |
404 | Sum of Left Leaves | BFS and DFS are provided |
669 | Trim a Binary Search Tree | DFS: if node.val < L, find right subtree; if node.val > R, find left subtree |
1022 | Sum of Root To Leaf Binary Numbers | DFS to reach the leaf nodes to get the root-to-leaf path |
654 | Maximum Binary Tree | DFS build root.left and root.right |
1008 | Construct Binary Search Tree from Preorder Traversal | DFS for find root.left and root.right |
993 | Cousins in Binary Tree | DFS finds depth and parent node |
637 | Average of Levels in Binary Tree | BFS for level traverse |
1325 | Delete Leaves With a Given Value | DFS check if node is leaf and node.val==target, then return None |
543 | Diameter of Binary Tree | Good Question, similar to 687. DFS for finding the longest path for left and right subtree |
572 | Subtree of Another Tree | DFS finds if left and right subtree are identical |
889 | Construct Binary Tree from Preorder and Postorder Traversal | The property of pre and post determines that we can split these two order into new subset and contruct left subtree and right subtree |
1026 | Maximum Difference Between Node and Ancestor | The definition of ancestor is important. We keep track of the min and max values along the path from root to leaf, then the max difference would be max-min |
508 | Most Frequent Subtree Sum | Bottom-up approach for getting all the subtree sums |
1372 | Longest ZigZag Path in a Binary Tree | The key is to analyse the basic unit structure. root->left-right, root->right-left. |
958 | Check Completeness of a Binary Tree | Level traverse and find the first None node, keep looking if valid nodes exisit after it. |
96 | Unique Binary Search Trees | DP solution The special property of BST determines that for root j==3, and node values range from 1 to 5, we have 2 left nodes and 2 right nodes. |
297 | Serialize and Deserialize Binary Tree | Preorder to serialize a tree and then dfs to find the left subtree and right subtree.in dfs, do not send a copy of data, keep the original |
652 | Find Duplicate Subtrees | Hashtable + subtree serialize |
863 | All Nodes Distance K in Binary Tree | Build graph and run dfs. |
450 | Delete Node in a BST | Two solutions provided: 1. inorder traverse+buildTree 2. DFS updates left and right nodes |
662 | Maximum Width of Binary Tree | Level order traverse + complete binary tree numbering |
106 | Construct Binary Tree from Inorder and Postorder Traversal | Similar to 889, find left nodes and right nodes subsets |
971 | Flip Binary Tree To Match Preorder Traversal | DFS, check current node and children |
95 | Unique Binary Search Trees II | Recursively build left and right subtrees |
1339 | Maximum Product of Splitted Binary Tree | Get top-down sum for each node and run dfs to break the tree into two |
1367 | Linked List in Binary Tree | Run dfs to detect whether starting at a node can find the pattern, meanwhile dfs stores the path it goes through |
1123 | Lowest Common Ancestor of Deepest Leaves | Bottom-up approach |
# | title | solved |
---|---|---|
206 | Reverse Linked List | Yes(remember the order) |
141 | Linked List Cycle | Yes |
142 | Linked List Cycle II | fast and slow pointers, math problem, good blog |
24 | Swap Nodes in Paris | Yes(prev, a, b) |
328 | Odd Even Linked List | Yes(break down to 2 linked list) |
237 | Delete a Node in a Linked List | Yes |
19 | Remove nth Node | Yes |
83 | remove duplicate numbers in linked list | prev + cur |
203 | Remove Linked List Elements | Yes |
2 | Add Two Numbers | get sum first and then make a linked list |
445 | Add Two Numbers II | same as 2 |
21 | Merge Two Sorted Lists | add the smaller one each time |
1171 | Remove Zero Sum Consecutive Nodes from Linked List | prefix sum is the key |
160 | Intersection of Two Linked Lists | if reach end, switch head |
92 | Reverse Linked List II | reverse first then concat three sub-link |
82 | Remove Duplicates from Sorted List II | prev+cur, dummy for first non-duplicated node |
148 | Sort List | medium |
86 | Partition List | medium, use prev1 and prev2 to make new list |
147 | Insertion Sort List | medium, prev.next = cur.next, insert cur.val into right place |
725 | Split Linked List in Parts | medium, first think: what is the length for each part? |
143 | Reorder List | medium, get two list, start from most left and most right |
# | title | solved |
---|---|---|
621 | Task Scheduler | Always process the most frequent jobs, good explaination here |
373 | Find K Pairs with Smallest Sums | The next smallest sum must be at either right or down directions. |
1046 | Last Stone Weight | Maintain a max heap |
703 | Kth Largest Element in a Stream | Maintain a min heap with fixed size k |
973 | K Closest Points to Origin | Maintain a max heap with size K, everytime, we pop the current largest value |
451 | Sort Characters By Frequency | Two solutions |
692 | Top K Frequent Words | Maintain min heap with size k |
767 | Reorganize String | Max heap to store most frequent letters |
313 | Super Ugly Number | Min heap, find values in the given primes closure |
1054 | Distant Barcodes | Same as 767, use prev variables to keep track of the previous number |
264 | Ugly Number II | Same as 313 |
787 | Cheapest Flights Within K Stops | Both DFS and BFS LTE |
295 | Find Median from Data Stream | Impressive solution, use max and min heap to maintain half numbers, top numbers at eahc heap will be numbers in the middle |
658 | Find K Closest Elements | Min heap |
4 | Median of Two Sorted Arrays | Max and min heap |
57 | Insert Interval | Merge |
# | title | solved |
---|---|---|
384 | Shuffle An Array | Yes |
398 | Random Pick Index | Yes |
382 | Linked List Random Node | Yes |
380 | Insert Delete GetRandom O(1) | Tes |
381 | Insert Delete GetRandom O(1) - Duplicates allowed | Yes |