The problem
Given an m×n grid of '1' (land) and '0' (water), count the number of islands — groups of adjacent lands connected horizontally or vertically.
Unlock the full guide
Premium members get every DSA, system design, company and role interview guide — plus AI practice, mock interviews, and analytics.
Unlock with Premium