Ctrl K
Problem

Land Regions on a Map

Medium · Land Regions on a Map

A map is given as a rectangular grid `terrain` with m rows and n columns. Each cell is the string '1' (land) or '0' (water). A land region is a group of '1' cells connected through horizontal or vertical neighbours; touching diagonally does not count. Everything outside the grid is water. Return the number of separate land regions.…

Solve the problem →