As reported: Goldman Sachs rounds (2025–2026): Number of Islands in an Analyst CoderPad (the interviewer preferred BFS over DFS to avoid stack overflow); counting connected components of a grid, number-of-islands style, in a Java Associate Superday DSA round; "a variation of Number of Islands" in an Analyst Superday DSA round.
Given an m × n grid of "1" (land) and "0" (water), return the number of islands — groups of land cells connected horizontally or vertically.
This is LeetCode 200 — Number of Islands.
Example 1
grid = [["1","1","1","1","0"],["1","1","0","1","0"],["1","1","0","0","0"],["0","0","0","0","0"]]
-> 1
Example 2
grid = [["1","1","0","0","0"],["1","1","0","0","0"],["0","0","1","0","0"],["0","0","0","1","1"]]
-> 3
Constraints: 1 ≤ m, n ≤ 300.
Code runner format: one JSON value per line: grid (LeetCode's test-case format). Implement numIslands(grid); the harness prints the result as JSON.