All topics
5 patterns · 24 problems

Arrays

The patterns behind most array and subarray problems — walk pointers, slide windows, and precompute totals to turn O(n²) into O(n).

01Pattern

Two Pointers

Walk two indices toward each other and skip the wasted work.

This patternO(n)naïve O(n²)

When to reach for it

  • You need to iterate with two indices, typically starting from opposite ends or different positions in the array.
  • The task involves comparing or manipulating elements from two different parts of the array at the same time.

Spot it in the prompt

The problem mentions a sorted array, or you need to compare elements from both ends of the array.

Easy Bespoke animation

Two Sum

LeetCode
Loading animation…

How to solve it

On a sorted array, put one pointer at each end and move them inward: if the pair sums too high move the right pointer left, too low move the left pointer right.

Open full solution

Practice · 5 problems

Select any problem to watch the technique run. marks a problem with its own bespoke animation.

02Pattern

Merge Intervals

Sort by start, then fold overlapping ranges into one.

This patternO(n log n)naïve O(n²)

When to reach for it

  • The problem involves intervals or ranges — time slots, scheduling, or overlapping events.
  • You need to combine, compare, merge, or find intersections between intervals.

Spot it in the prompt

The input is intervals represented as start/end pairs, and the task is about combining or manipulating those intervals.

Medium Bespoke animation

Merge Intervals

LeetCode
Loading animation…

How to solve it

Sort by start time, then walk the list folding each interval into the current one whenever they overlap.

Open full solution

Practice · 4 problems

Select any problem to watch the technique run. marks a problem with its own bespoke animation.

03Pattern

Sorting

Impose order first so the rest of the problem falls out.

This patternO(n log n)naïve O(n²)

When to reach for it

  • Arranging elements in a specific order simplifies searching, counting, or comparing them.
  • Sorting by some criteria unlocks the solution or optimizes the operations that follow.

Spot it in the prompt

The problem hints the array needs to be sorted first, or that ordering the data would make the solution obvious.

Medium Bespoke animation

Sort Colors

LeetCode
Loading animation…

How to solve it

The Dutch national flag algorithm: low, mid and high pointers partition 0s, 1s and 2s into place in a single pass.

Open full solution

Practice · 5 problems

Select any problem to watch the technique run. marks a problem with its own bespoke animation.

04Pattern

Sliding Window

Keep a moving window and update the answer as it slides.

This patternO(n)naïve O(n²)

When to reach for it

  • The problem involves contiguous subarrays or substrings where you slide a window across the input.
  • You need to track a subset of elements that satisfies a specific condition as it moves.

Spot it in the prompt

The input involves contiguous subarrays, a "window" that slides across the array, or properties like "maximum sum" or "minimum length".

Medium Bespoke animation

Minimum Size Subarray Sum

LeetCode
Loading animation…

How to solve it

Grow the window to the right until the sum reaches the target, then shrink it from the left as far as possible — the shortest valid window is the answer.

Open full solution

Practice · 5 problems

Select any problem to watch the technique run. marks a problem with its own bespoke animation.

05Pattern

Prefix Sums

Precompute running totals to answer range queries in O(1).

This patternO(1) / querynaïve O(n) / query

When to reach for it

  • You need cumulative sums or averages over subarrays, or must answer many subarray-sum queries efficiently.
  • Precomputing aggregate values up front can cut the time complexity of repeated range operations.

Spot it in the prompt

The problem mentions subarray sums, cumulative sums, or range sums, and hints that precomputing sums would speed things up.

Medium Bespoke animation

Range Sum Query - Mutable

LeetCode
Loading animation…

How to solve it

Prefix sums answer any range in O(1), but a single update forces you to rebuild them in O(n) — a Fenwick (binary indexed) tree keeps both query and update logarithmic.

Open full solution

Practice · 5 problems

Select any problem to watch the technique run. marks a problem with its own bespoke animation.

You've got the patterns

Patterns get you through the screen. Shipping gets you hired.

FDE Coach is a cohort-based program in frontend, backend, AWS, and AI where you build real products and get referred to 200+ hiring partners. The free live workshop is the fastest way to see how we teach.

750+ engineers trained · frontend, backend, AWS & AI

August 15 · 0d left
Enroll Now