All topics
5 patterns · 23 problems

Binary Search

Halve the search space every step — on sorted arrays, and on answers, ranges, and allocations.

03Pattern

Allocation Problems

Search the smallest max that a greedy split allows.

This patternO(n log(range))

When to reach for it

  • Involves dividing resources or items among multiple entities while optimizing a certain criterion.

Spot it in the prompt

Look for scenarios where resources need to be distributed among entities with certain constraints, and the goal is to optimize a certain criterion, such as minimizing the maximum or maximizing the minimum.

Medium

Koko Eating Bananas

LeetCode
Loading animation…

How to solve it

Animation: Allocation Problems technique

Binary search the eating speed; for each candidate rate sum the hours needed and shrink toward the smallest rate that still finishes in time.

Open full solution

Practice · 4 problems

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

04Pattern

Counting Occurrences

Find boundaries with binary search, then subtract indices.

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

When to reach for it

  • Involves counting the number of occurrences of a specific value or satisfying a certain condition.

Spot it in the prompt

Look for scenarios where you need to count occurrences or determine the frequency of certain elements/values in a sorted array or range.

Medium

Find First and Last Position of Element in Sorted Array

LeetCode
Loading animation…

How to solve it

Animation: Counting Occurrences technique

Run two binary searches for the leftmost and rightmost target indices; their difference gives the occurrence range.

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