- Consider using HashMap when comparing two strings or arrays.
- When handling string problems, ask if it is ASCII. Use an array of length 256 if it is.
- When comparing two strings or arrays, sort them first.
- Using StringBuffer for the temporary result for string concatenate.
- Prepend a dummy node for linked list problems.
- Remember integer might be negative!
- Computer cannot accurately represent float/double, use epsilon for equality check.
- Interval intersection: 1) sort by start point, binary search the end point 2) sort both start and end points, go through the array, for start point i++, for end point i--.
- For interval scheduling, use greedy algorithm: earliest time first.
- Median for a random generated integer stream, using a min and a max heap.
- For kth smalless element, using the quicksort partition or a k maxheap.
- Consider suffix tree or trie, when dealing with string match problems.
- Consider segment tree, when needs preprocessor and min/max value in a range.
- Randomly generate m elements from array of n, using the array shuffle algorithm.
- Preoder, inorder, postorder tree traverse, using a stack and another pointer to remember what is the prev node.
- If elements have slightly difference with other, construct a graph and find the hamilton cycle or Eulerian cycle.
- When looking for string with the same characters, sort the string first.