Binary Search
- Binary Search 模板 //背
- Binary Search in Rotated Array
- Find K Smallest Element in BST
Follow up: What if the BST nodes are updated frequently, or the FindKthSmallestElem() is called frequently. We can use QuickSelect() and preprocessint to record # of subtree nodes of each BST node ???
Binary Tree
- Binary tree in-order traversal (non-recursion) //重点背
pre-order and post-order traversal (non-recursion) 最好也背 - Binary search tree iterator //背
- Lowest Common Ancestor
Word 4大重点题: //每题至少5遍
- Word Pattern I, II
- Word Search I, II
- Word Ladder I, II
- Word Break I, II //30分钟AC
Regular Expression Matching //至少5遍,30分钟AC
Wildcard Matching //DP
String Permutation II
Merge Two Sorted Arrays
Merge K Sorted Array //3种方法
Merge Two Sorted Lists
Merge K Sorted List //3种方法
a) Priority Queue
b) Merge (from bottom to top)
c) Merge Sort (from top to bottom)
Merge Two Sorted Interval Lists
Merge K Sorted Interval Lists //use cache? 3种方法
Maximum Subarray //use Prefix Sum
Best time to Buy and Sell Stock //use Prefix Sum, similar to Maximum Subarray
Find the Kth Largest Number in an Unsorted Array //Quick Select
Find the Median of K Sorted Arrays //use Binary Search !!!
//cannot use the solution of find the Kth largest number of N Sorted Arrays
Binary Index Tree
update(), getPrefixSum, SetRangeSum() //背
LRU Cache //高频中的高频
a) Doubly Linked List + Hash
b) Single Linked List + Hash
数据流问题
- Find Unique Character in a String
//不能做两次遍历 - Insert(), Delete() and GetRandom()
K Closest Points //3 solutions
a) Simple Sort O(nlogn)
b) Quick Select O(n)
c) Priority Queue O(nlogn)
- Priority Queue Improved Version
Sorting
Quick Sort //极其重要 背 记得是left<=right, 等于情况两边都要去
Merge Sort
Bubble Sort //掌握
RainBow Sort
Counting Sort
个人总结:
binary search用于已经排好序的场合,比如Median of two Sorted Arrays
quick select法通常用来在未排序的数组中寻找第k小/第k大的元素。
对于诸如merge K sorted arrays/interval lists之类的问题, 可用priority_queue+tuple。
一些容易混淆的题目:
1)
Longest Common Substring (DP, 不用考虑DP[i-1][j]和DP[i][j-1])
Longest Common Subsequence ((DP, 需要考虑DP[i-1][j]和DP[i][j-1]))
Longest Increasing Subsequence (用DP或二分)
Longest Continuous Increasing Subsequence (用一个循环遍历即可)
Longest Common Prefix (用HashMap或Trie)
LintCode 402 Continuous Subarray Sum 这题不要跟LIS混淆,并且这题有2个变种
LintCode 558 求固定长度的连续序列的最大和
LintCode 403 Continuous Subarray Sum II (LintCode 402 +循环数组)
左右侧最近更大数问题(单调递增栈)
直方图求最大矩形 (单调递增栈)
二维蓄水池最大蓄水量(反向双指针或先算最大高度然后从左右两边分头算)
一些跟数学相关的问题
- 素数相关问题
- 随机数相关问题
- 几何相关问题