All topics
7 patterns · 35 problems

Priority Queues

Heaps that keep the best element one pop away — top-K, streaming medians, merges, and Dijkstra.

01Pattern

Finding Kth Largest/Smallest

Keep a heap of size K, ignore the rest.

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

When to reach for it

  • You have a large dataset, and you need to efficiently find the Kth largest or smallest element.

Spot it in the prompt

Look for problems where you need to track the K largest or smallest elements while processing the dataset.

Medium

Kth Largest Element in an Array

LeetCode
Loading animation…

How to solve it

Animation: Finding Kth Largest/Smallest technique

Maintain a min-heap of size K; push each value and pop when it exceeds K, leaving the Kth largest at the root.

Open full solution

Practice · 5 problems

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

02Pattern

Top K Frequent Elements

Count first, then heap by frequency.

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

When to reach for it

  • You're analyzing data and need to identify the most frequently occurring elements.

Spot it in the prompt

Look for problems where you need to track element frequencies and select the top K elements based on occurrence count.

Medium

Top K Frequent Elements

LeetCode
Loading animation…

How to solve it

Animation: Top K Frequent Elements technique

Build a frequency map, then bucket-sort by count or keep a size-K heap to extract the K most common values.

Open full solution

Practice · 5 problems

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

03Pattern

Merge K Lists

One heap of list heads, merge in order.

This patternO(n log k)naïve O(nk)

When to reach for it

  • You have K sorted lists and need to merge them into a single sorted list.

Spot it in the prompt

Look for problems where you're required to merge multiple sorted sequences while maintaining order.

Medium Bespoke animation

Merge Intervals

LeetCode
Loading animation…

How to solve it

Sort intervals by start, then sweep and merge each into the previous whenever its start overlaps the running end.

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 Maximum/Minimum

Track the window extreme without rescanning.

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

When to reach for it

  • You need to find the maximum or minimum element in all contiguous subarrays of size K.

Spot it in the prompt

Look for problems where you maintain a sliding window of fixed size and efficiently find the maximum or minimum element.

Hard

Sliding Window Maximum

LeetCode
Loading animation…

How to solve it

Animation: Sliding Window Maximum/Minimum technique

Maintain a decreasing deque of indices; the front holds the window max, and stale or smaller indices are dropped.

Open full solution

Practice · 5 problems

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

05Pattern

Design Problems

Build a structure with a heap at its core.

When to reach for it

  • You're tasked with designing a custom data structure using priority queues to solve specific problems efficiently.

Spot it in the prompt

Look for problems where you need to design a data structure using priority queues for various functionalities.

Medium

Design Twitter

LeetCode
Loading animation…

How to solve it

Animation: Design Problems technique

Store timestamped tweets per user and merge followed users' feeds with a heap to surface the 10 most recent posts.

Open full solution

Practice · 5 problems

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

06Pattern

Construction and Manipulation

Greedily place the most frequent item first.

When to reach for it

  • You need to construct, modify, or manipulate data structures using priority queues efficiently.

Spot it in the prompt

Look for problems where you construct or manipulate data structures using specific rules using priority queues.

Medium

Task Scheduler

LeetCode
Loading animation…

How to solve it

Animation: Construction and Manipulation technique

Greedily schedule the most frequent task via a max-heap, filling cooldown gaps with other tasks or idle slots.

Open full solution

Practice · 5 problems

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

07Pattern

With Graphs

Always expand the cheapest frontier node.

This patternO(E log V)

When to reach for it

  • You need to solve graph-related problems efficiently using priority queues for operations like Dijkstra's algorithm or finding minimum spanning trees.

Spot it in the prompt

Look for problems where you process nodes or edges based on their weights or distances in graph-related scenarios.

Medium

Network Delay Time

LeetCode
Loading animation…

How to solve it

Animation: With Graphs technique

Run Dijkstra from the source with a min-heap of arrival times, then return the maximum settled distance.

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