O43
Number of Islands
Problem Statement & Objective
Given an m x n 2D binary grid grid which represents a map of '1's (land) and '0's (water), return the number of islands.
Function Signature (Python)
num_islands(grid: list[list[str]]) -> intInput & Output Contract
Output Rule:Ada sayısı tam sayısı.
System Constraints
m == izgara.length, n == izgara[i].length
1 <= m, n <= 300
izgara[i][j] ∈ {'0', '1'}Example Execution Walkthrough
izgara = [
['1','1','0','0','0'],
['1','1','0','0','0'],
['0','0','1','0','0'],
['0','0','0','1','1']
] -> 3 adaExample Test Scenarios (3)
Example 1: Tek Büyük Ada
Input:
[[["1","1","1","1","0"],["1","1","0","1","0"],["1","1","0","0","0"],["0","0","0","0","0"]]]Expected Output:
1Example 2: 3 Ada
Input:
[[["1","1","0","0","0"],["1","1","0","0","0"],["0","0","1","0","0"],["0","0","0","1","1"]]]Expected Output:
3Example 3: Yalnız Su
Input:
[[["0"]]]Expected Output:
0