POST 1 of 5 MorningCareerRecap
8 patterns that solve 80% of interview problems
After two weeks of DSA, here's the pattern map I keep coming back to. Eight patterns. They cover 80% of leetcode-medium problems and the vast majority of coding interviews. One — hash map / set. O(1) lookups. Replace 'in list' with 'in set'. Two-sum, dedup, group-by, anagram detection. The single most common Big-O upgrade. Two — two pointers. Slow/fast for cycles. Opposite ends for sorted-array problems. Same direction for sliding window. Three — sliding window. The pattern for 'best subarray with constraint X'. Variable window with for-loop + inner while-loop is the standard shape. Four — stack. Match-and-pop. Parentheses, expression parsing, undo/redo, monotonic stack for next-greater-element problems. Five — BFS. Shortest path on unweighted graphs and grids. Level-order traversal of trees. The deque + seen set + while-loop template. Six — DFS. Recursion or explicit stack. Tree traversals, connected components, backtracking. Seven — binary search. Find an element in a sorted array. Search the answer space when feasibility is monotonic. Half-open template, while lo < hi, lo = mid+1 or hi = mid. Eight — DP. Recursion + memoisation. State as one English sentence first. Top-down with lru_cache or bottom-up with loops. Most leetcode mediums map to one (or two) of these patterns. The skill that makes interviews easier isn't memorising algorithms — it's recognising which pattern applies. Five minutes thinking about the pattern beats fifty minutes coding the wrong approach. The further skill — knowing when patterns DON'T apply, and what does. Brute force, math reasoning, greedy, divide and conquer. The eight above are the bread and butter; the rest is the spice.
#DSA#Algorithms#Python#100DaysOfCode#CodingInterview#CodingInterview