NewProject Coding is here — build features and fix bugs in real codebases with an AI assistantSee what's new

(This question is a variation of the LeetCode question Number of Islands. If you haven't completed that question yet, it is recommended to solve it first.)

You are given a m × n 2D grid where each cell contains either a positive integer or 0. A cell with a positive integer represents part of an island, while a cell with 0 is water.

Test Cases
Input
Output
Expected