My notes and cheat sheets for algorithms.
Arrays/Strings
- If it says longest/shortest of sub string/array, its a sliding window problem
- If it says "Pattern of length k", its a sliding window problem
- Buy/Sell stock is a sliding window problem
- If it says "find more than 2 values that equal x" its probably a 2 pointer
- Two pointers usually starts at (l_point, r_point = 0, len(arr)-1). But not always
- (array_1.extend(array_2)) is much faster than (array_1 = array_1 + array_2)
Graphs
- If it says "nodes from 0 to n", consider Union Joins.