Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

SubArray Problem

Basically for all array questions, especially subarray:

1. sliding window, where we shrink the window or reset the pointer base on certain rules
2. Sliding window + hashmap (strings /distinct/repeat character questions)
3. prefix sum + hashmap (subarray sum equals k, count number of subarrays xxx, maximum size
subarray equals k)
4. DP style, understanding a increment of i yields i+1 extra subarrays, understand Kadanes,
easiest to spot among all but hardest to implement sometimes (variant of LCS , 1D max min
store dp, stock games, xxx partitioning (i,j))
5. difference array, segment trees, for range query of range update advance questions
6. Greedy, the hardest to prove but most simple and elegant
7. Most unintuitive, monotonic queue (sliding window maximum) , monotonic stack (query of
8. Sorted arrays ~ Binary search
9. multiple sorted arrays ~ two pointers, compare and move pointers / heap queues

Interval Problems

Check if sorting is required(mostly yes)


Check if sorting is required by start or the end

Try greedy or DP

BFS
BFS is used to find the smallest distance

You might also like