codeLeetCode Pattern Hub

LeetCode Patterns Guide

This is not just a pattern index. It is an interview-oriented guide to when a pattern should come to mind, why it works, where it breaks, and how to practice it efficiently.

Core patterns

12+

Problem pages

64+

Practice flow

Recognize -> solve -> review

Common target complexity

O(n) / O(log n)

Pattern Index

Each pattern page goes beyond a template and explains recognition signals, common variants, likely traps, and a practical practice order.

view_weekSliding Window
50+

Subarray and substring problems with contiguous ranges.

The problem asks about a contiguous range, substring, or subarray.

Open the pattern breakdownarrow_forward
compare_arrowsTwo Pointers
60+

Pointer movement on arrays, strings, and linked structures.

The answer depends on comparing two positions and deciding which side should move.

Open the pattern breakdownarrow_forward
searchBinary Search
40+

Monotonicity, boundary search, and answer-space search.

You can define a predicate that changes only once across the search space.

Open the pattern breakdownarrow_forward
grid_viewDynamic Programming
200+

State design, recurrence, and transition order.

You are optimizing, counting, or checking feasibility over many overlapping subproblems.

Open the pattern breakdownarrow_forward
account_treeBFS / DFS
80+

Traversal patterns for trees, graphs, and grids.

The input is a tree, graph, matrix, or implicit graph of states.

Open the pattern breakdownarrow_forward
hubUnion Find
30+

Connectivity and component merging problems.

The problem is about connectivity after repeated merge operations.

Open the pattern breakdownarrow_forward
layersHeap / Priority Queue
40+

Repeatedly access the current min, max, or top-k frontier.

You repeatedly need the current smallest, largest, or earliest finishing item.

Open the pattern breakdownarrow_forward
stacked_bar_chartMonotonic Stack
25+

Nearest greater/smaller and boundary discovery.

The problem asks for the next greater, next smaller, or nearest boundary element.

Open the pattern breakdownarrow_forward
functionsPrefix Sum
35+

Range sums, hash + prefix counts, and query compression.

The problem asks for many range sums or counts over ranges.

Open the pattern breakdownarrow_forward
trending_upGreedy
45+

Local choices backed by exchange or boundary arguments.

A local choice seems obvious and you can argue why delaying it never helps.

Open the pattern breakdownarrow_forward
undoBacktracking
55+

Systematic search with choice, recurse, and undo.

The problem asks for all combinations, permutations, subsets, or valid constructions.

Open the pattern breakdownarrow_forward
memoryBit Manipulation
30+

Bit tricks, state compression, and integer-level reasoning.

The problem talks about subsets, masks, parity, or binary states explicitly.

Open the pattern breakdownarrow_forward

A more interview-effective practice order

1

Start with sliding window, two pointers, and binary search to improve pattern recognition speed.

2

Then move into dynamic programming and BFS/DFS for state design and traversal thinking.

3

Finish with union find, monotonic stack, heaps, and backtracking to round out hard-problem coverage.

How to use this pattern library more effectively

  • check_circleUse pattern pages to build recognition first, then jump into representative problems for full solutions and code.
  • check_circleMastering three to six good representative problems per pattern is usually better than blindly grinding dozens.
  • check_circleIf your interview is close, prioritize high-frequency medium problems and revisit the most common follow-ups later.

Bridge into deeper prep surfaces

LeetCode Patterns Guide | Practical Interview Frameworks - Interview AiBox