-
Notifications
You must be signed in to change notification settings - Fork 0
0 Overview
Tim_Gao edited this page Sep 23, 2016
·
30 revisions
-
Bit manipulation
Basically the idea is examining the bits of each number- Majority Number
- Single Number II and Single Number III
-
HashMap + two pointers
To process substring problems. Use HashMap to store characters information and use two pointers to update the HashMap.- Longest Substring with at most two distinct characters
- Longest substring without repeating characters
- Minimum window substring
- Longest Substring with At Most K Distinct Characters
-
Stack
- Largest Rectangle in histogram
- Largest valid parentheses
- Trapping rain water
Store index in stack
-
compute modulo
Basically use (n-1)%base to deal with edge cases- Excel Sheet Column Title
- permutation sequence, given a number n, return the nth permutation sequence
-
Divide and Conquer
- Different Ways to Add Parentheses (this one is good)
Basically divide the input into two by an operator and then fed the substrings to the same function
a+c*c+d*e --> (a) + (c*c+d*e) or (a+c) * (c+d*e)... -
Burst Balloons
This is pretty special divide and conquer
- Different Ways to Add Parentheses (this one is good)
-
Memorized Dynamic Programming
Basically take advantage of the results computed before. (what kind of DP is not suitable for memorized DP)- Guess Number Higher or Lower II
- IntegerBreak
-
Combination sum like algorithm
- Subset
- Coin Change
-
Memorized DFS
Think about the time complexity of memorized DFS.- Longest increasing path in a matrix
This is pretty good. One thing that worth thinking is in what situation we can use memorized DFS.
- Longest increasing path in a matrix
-
MergeSort plus counting
- count of range sum
Another way to merge two subarrays. Instead of using two pointers, you can iterate through one of them. Another important thing is how to calculate the number of subarrays whose sum is in[lower, upper]. You don't have to start from the very beginning to count for each i in the first array. - Count of smaller numbers after self
pay attention to the case where nums[p1] == nums[p2], which one goes to the result array first
- count of range sum
-
List all possible solution
- Create Maximum Number
The most difficult part is how to merge two subarrays to create the maximum number (I made mistakes at this step every time)
- Create Maximum Number
-
Stack + HashMap
The idea is create a hash map storing all the characters and then use a stack to get a max or min order. I feel like that Stack is extremely good for ordering things- Remove Duplicate Letters
- Create Maximum Number
-
plain two pointers
- Trapping rain water nice idea
-
Heap
- Merge k sorted list
- Find Median from Data Stream
-
Binary Search
Binary search comes in different ways. The following examples should give you an good idea about the binary search problem patterns.- Find peak element
-
BFS
- Walls and Gates
This problem is nice. It has multiple initial values which is the box that with value 0. Then start from all the boxes that has value 0 (gates) then do BFS. Multiple point BFS.
- Walls and Gates
-
Binary search tree
Use a count in each node. You can walk the tree and count the number of elements smaller or greater than the current value. The nice about this technique is that you can preserve the order of the elements you insert into the BST.- Count of smaller number
-
Largest BST Subtree
For BST problem, if you want to check if it's a BST or not, you have to get max and min of all the descendantes. You can not just look at it's left and right children and decide.
-
Divide Triple into Pairs
The idea is divide triple into two paris and put all the pairs in one container. Sort all the pairs properly and iterate through the container in order and provide you the info you want.- The skyline problem
- Range Addition
- Course Schedule
- Number of flights in sky
-
Use String as a pattern
- Group Shifted Strings
-
DFS
DFS comes in different forms.- Smallest Rectangle Enclosing Black Pixels
This DFS is pretty interesting. You don't have to find all possible routes. you just need to cover every back pixel. So you don't have to set visited[x][y] to false when you exit the DFS method. - Expression add operator
Memorized the previous operator and deal with*carefully. The first number also need to generated before doing dfs
- Smallest Rectangle Enclosing Black Pixels
-
Sum array plus HashMap or TreeMap
*Maximum Size Subarray Sum Equals k