Dsa
Graphs Dfs
Easy
Building Bridges
You are tasked with building bridges between islands represented in a connected grid. Write a function to find the number of bridges that can be built (any two points across the grid that are not diagonally aligned count as a bridge). An island is represented by '1' and water by '0'.
Input:
First line contains two integers m and n (1 <= m, n <= 100).
The next m lines represent the grid of '0's and '1's.
Output:
Print the number of possible bridges.
Example:
Input:
3 3
1 0 1
0 0 0
1 0 1
Output:
4
Key concepts
graphsdfsbridges
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