Search⌘ K
AI Features

DIY: Walls and Gates

Explore how to solve the Walls and Gates problem, where you update a 2D grid to reflect shortest distances from empty rooms to gates. This lesson helps you understand problem-solving techniques for grid-based challenges frequently asked in coding interviews at companies like Amazon. Gain confidence in applying breadth-first search and handling constraints in Swift.

We'll cover the following...

Problem

You are given a m×nm \times n grid represented by a 2D array named rooms. The grid represents rooms where a cell can either be a wall, a gate, or an empty space. The rooms are initialized with these three possible values.

Values Represents
1-1 A wall or an obstacle
0
...