Back to all patterns

Multi-source BFS

2 problems • Practice on LeetCode to earn credits

About This Pattern

Master the Multi-source BFS pattern by practicing these problems organized by difficulty.Focus on the Key Signals - these are the indicators that tell you when to use this pattern.

Medium (2)

Walls And Gates

Fill distances to nearest gate in a 2D grid with rooms, walls, and gates.

Key Signals:

Start BFS from all gatesUpdate distancesQueue all sources
Rotting Oranges

Find minimum time for all oranges to rot (rot spreads to adjacent oranges each minute).

Key Signals:

BFS from all rottenTrack time levelsCount fresh oranges