Question
- Longest Increasing Subsequence -- O(nlogn) : the most important thing is the tail of number in a increasing sequence
611.Valid Triangle Number — focus on the key point, in this question, the key point is the longest edge since a + b > c, and a & b are the shorter edge
653.Two Sum IV —
252.Meeting Rooms —
404.Sum of Left Leaves — global variable => local
Medium
647.Palindromic Substrings — the characteristics of Palindrome. outside or inside is important? redundant steps? if we want to expend from middle to the ends, where is the center
238.Product of Array Except Self — using division is the simplest way?
477.Total Hamming Distance — brute force might time exceeded
377.Combination Sum IV — 1. the order of if statement is very important, you should arrange them carefully 0 is one of return values, so you cannot judge by 0 => null
525.Contiguous Array — plus while encounter 1 is not the point ! minus while encounter 0 is the point!
334.Increasing Triplet Subsequence — while encounter the least number, should i update? (is it important?)
78.Subsets — back track
292 Nim Game — observe the rule, which case you always cannot win?
17.Letter Combinations of a Phone Number — thinking about DFS and BFS way
161.One Edit Distance — The order problem !! So maybe you can observer the rules.
750.Number Of Corner Rectangles — you don't have to find -> v <- this kind of order. find it with pair
79.Word Search — the order of if, using OR to judge for return value
139.Word Break — start with check every combinations the optimizing it
33.Search in Rotated Sorted Array — input array is separated into two parts, so does your code
380.Insert Delete GetRandom O(1) — if you have a hole in the middle of list, them fill it!
236.Lowest Common Ancestor of a Binary Tree —
523.Continuous Subarray Sum — how to determine the dynamic target, and you have to consider the corner case!
91.Decode Ways — substring has different index other than array! careful!
297.Serialize and Deserialize Binary Tree — why DFS is faster than BFS?
still can't figure out the best solution:
221.Maximal Square — if you use the future info, maybe you can try yo think about using the previous info (#better dp)
341.Flatten Nested List Iterator — It's a DFS problem
285.Inorder Successor in BST — it's a BST, so you can utilize the special feature of it.
25.Reverse Nodes in k-Group — the details about reverse more than k nodes
============ Easy ============
28.Implement strStr() — the most complex way is using KMP (Knuth-Morris-Pratt)
234.Palindrome Linked List — the feature of palindrome -> reverse the target will as the same as original one
168.Excel Sheet Column Title — because there is no zero in this rules, you should adjust this to your algorithm
653.Two Sum IV - Input is a BST — binary search
============ Medium ============
621.Task Scheduler — You should use observation, and find out the most important key point.
15.3sum — if it is a sorted array and it need to find out a pair, there is a classic way to solve it -- two pointer
277.Find the Celebrity — narrow down the range is a good solution to speed up
721.Accounts Merge —
285.Inorder Successor in BST — This problem is to find the ceiling of element
33.Search in Rotated Sorted Array — because it is rotated sorted array, the feature is one of the side of array is sorted. Therefore, you need to use this feature to cover all the cases
75.Sort Colors — three way partition
523.Continuous Subarray Sum — the feature of remainder is that if there are two numbers that have the same mods, it means that the difference between the numbers is the divisor
785.Is Graph Bipartite? —instead of using two sets to represent two group, do you have another way which can combine with visited array.
477.Total Hamming Distance — you just need to know how many numbers of difference between these numbers
261.Graph Valid Tree — make sure you understand well about valid tree. The edge of tress are undirected.
Valid Tree definition: There is no circle in the tree and there is only a tree.--> Union find
825.Friends Of Appropriate Ages — categorize them first, then deal with the duplicate ones
50.Pow(x, n) — you have to consider the corner case, according to the positive and negative sign
238.Product of Array Except Self — how can we multiply other elements without loop
714.Best Time to Buy and Sell Stock with Transaction Fee —
673.Number of Longest Increasing Subsequence — you must figure out the rules to calculate the count of Longest Increasing Subsequence
801.Minimum Swaps To Make Sequences Increasing —
127.Word Ladder — BFS, shortest transformation sequence => find the shortest past, length(wordlist) * length(wordlist) => 26*3
763.Partition Labels — use all the information you already have
============ Hard ============
301.Remove Invalid Parentheses — if you just list all the possibilities and keep find out the minimum remove, it is too slow. However, what would you do that can make sure every time you keeping or removing the character is reasonable.
273.Integer to English Words — you should consider more test case that might cause wrong answer including the space problem
10.Regular Expression Matching —
410.Split Array Largest Sum — recursion to dp is a very important part that you need to be careful about the initial condition and the dp direction
689.Maximum Sum of 3 Non-Overlapping Subarrays — convert O(n3) -> O(n), you can use dp to solve another method
282.Expression Add Operators — the combination of number is prior to the operators
Amazon
============ Medium ============
240.Search a 2D Matrix II — all integer are all sorted from left to right and top to down, so you must use this feature
74.Search a 2D Matrix — all integers are sorted, therefore you should treat them as a list and use / % to group them and identify the location
451.Sort Characters By Frequency — bucket list
516.Longest Palindromic Subsequence — do you need the past information, then it's a bottom up question, how about use the index of "start & end" to save the past information and transform into dp question
694.Number of Distinct Islands — the way that you remember the shape of island can be "UDLR" and "B" as the end of a direction
742.Closest Leaf in a Binary Tree — every node has a number to represent the how many edges between root, but how to set the calculating rules?
545.Boundary of Binary Tree — leaf and node can be separated due to the different behavior, node will be all in the recursion chain, however, leaf will end the recursion. Also, the function that added before recursion and after recursion will behavior different.
186.Reverse Words in a String II — reverse the whole string first, then you can control the words's length and the only job left is reversing each word.
2.Add Two Numbers — don't forget about the dump head
** 306.Additive Number — startsWith is a good function to examine the following string and if you concern about the length of the initial two number then you have to give them the range restriction indeed
** 842.Split Array into Fibonacci Sequence — you have to deal with the cases that input is a long string and it might exceed the MAX value of integer and long, while facing the situation that input type is string and the output type is int, you must deal with the boundary of integer carefully!!!!!
73.Set Matrix Zeroes — one of the methods that can speed up the algorithm is split/divide the for loop into several
742.Closest Leaf in a Binary Tree — if you need some information that the class structure can not afford, then you can create by your own
449.Serialize and Deserialize BST — is quite similar with 297.Serialize and Deserialize Binary Tree, but you should utilize the benefit of BST , min and max
**536.Construct Binary Tree from String — It's hard to manage the index of string to build the tree, the end of a constructing node character will be ')'
**776.Split BST — using the TreeNode array as the passing value, due to the fact that each node will treat the TreeNode array as the same rules: split[0] is small/eq and split[1].
**138.Copy List with Random Pointer
355.Design Twitter — you can construct new classes to fulfill the requirement
============ Hard ============
42.Trapping Rain Water — you can go both way at the same time and solve the problem that go from low to high
239.Sliding Window Maximum — think out side the box, queue can store the information of value, however, the index is more important than value since there is a limited window size. Also, you should keep the useful value in the data structure and discard useless things
675.Cut Off Trees for Golf Event — In BFS, you should set the visited be true as soon as it added to the queue, then it will be faster than poll out the element and set it as true. BFS with queue is better than recursive
517.Super Washing Machines — I don't know how to set the rules that some of scenario is two machines will pass a clothe to the same machine and some of scenario is every machine need to pass to different machine
146.LRU Cache — if you only use a PriorityQueue, the time complexity will be linear. However, the time complexity can be reduced to O(1). Therefore, you should use a better data structure to handle the cache.
Others
============ Medium ============
179.Largest Number — you should let compare do the things for you, don't list all the rules
Rotate Array — how to deal with when k > nums.length? how to go through every number by once in loop?
Min Stack — Do I need to update min number every time it pop? Or there should be a better way? observe the rule!
253.Meeting Rooms II — when start and end is at the same time, which first?
- Arrays.sort(start) Arrays.sort(end)
56.Merge Intervals
- ****Use the stack and search just like 2sum without dumping all the value out in the beginning.
653.Two Sum IV - Input is a BST
- weird question that i cannot get it
157.Read N Characters Given Read4
151.Reverse Words in a String