BugForge
DSA

Count Delivery Zones

MediumBFSDFSgrid 00:00

The map is a grid of '1' (served) and '0' (not served). Cells connect up/down/left/right. Return the number of connected served zones.

Signature

countZones(grid: string[]) → int
Example 1
grid = ["11000","11000","00100","00011"]
output = 3
3 zones
Example 2
grid = ["111","010","111"]
output = 1
1 zone

Constraints

  • 1 ≤ rows, cols ≤ 300
Run checks the examples. Submit runs every hidden test (17, including large inputs that catch slow solutions).