Lesson 070

Algorithm Patterns

Recognize · Reuse · Solve

1:00

Four reusable problem-solving patterns — frequency counter, two pointers, sliding window, and dynamic programming — and the keywords that signal which one to reach for.

By the end, you can

  • Explain why the right algorithmic pattern typically converts O(n²) brute force into O(n).
  • Describe the core mechanic of each of the four patterns and name its canonical use-case.
  • Identify which pattern applies to a problem by spotting its recognition-map keywords.
  • Trace the two-pointer decision logic (sum too small → move L right; too large → move R left).
  • Fill in a one-dimensional DP table using the recurrence ways(n) = ways(n-1) + ways(n-2).
  • Explain why unmemoized recursion on overlapping subproblems is O(2ⁿ) and how memoization collapses it to polynomial time by caching and reusing each subproblem's result.
  • Distinguish the fast & slow pointer variant from the converging-pointer variant and state what problem each one solves (cycle detection / finding the middle vs. pair-finding in a sorted array).
  • Recognize when greedy fails and explain why dynamic programming is needed instead.
Up next in Recursion, Paradigms & Algorithm Analysis
Questions or feedback?