Dsa
Graphs Bfs
Warm-up
Island Perimeter
Given a grid of 0s and 1s, where 1 represents land and 0 represents water, calculate the perimeter of all the islands in the grid. The perimeter of an island is the total number of edges that touch water or the grid's boundary. The input ends with a line containing '0'. Return the total perimeter of all islands in the grid.
Example Input:
1 1 0 0
1 1 0 0
0 0 0 0
0 0 0 0
0
Example Output:
8
Key concepts
graphsbfsisland
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now