Engineered
Algorithm Patterns

Introduction

A quick guide to what algorithm patterns are and how they help you solve coding problems faster.

What is an Algorithm Pattern?

An algorithm pattern is a repeatable recipe or template for solving common coding problems.

Instead of guessing or starting from scratch on every problem, patterns give you a proven game plan. Most interview and LeetCode problems are just variations of a few core patterns.

Key Idea

Don't memorize individual problems. Learn the patterns behind them so you can solve hundreds of problems with the same core technique.


Why Use Patterns?

  • Faster Solutions: Spot what a problem needs in seconds instead of getting stuck.
  • Better Performance: Avoid slow nested loops (O(n2)O(n^2)) and write fast, clean code (O(n)O(n)).
  • Clear Game Plan: Know right away which data structure to pick and how to walk through the data.

Quick Cheat Sheet

Here is how to spot the right pattern based on what the problem asks:

If you see...Try this patternWhy it works
Comparing counts, anagrams, duplicatesFrequency CountersUses a hash map to count items in one pass
Sorted list, finding pairs, opposite endsTwo PointersMoves two pointers to avoid checking every pair
Contiguous sub-array, longest substringSliding WindowExpands and shrinks a window without re-scanning

What We'll Cover Next

In this section, we will learn the top 3 essential patterns step-by-step:

  1. Frequency Counters: Count items with hash maps to avoid nested loops.
  2. Two Pointers: Walk through sorted data efficiently using two pointers.
  3. Sliding Window: Track a moving window over an array or string.

How is this lesson?