Dsa
Graphs Bfs
Easy
Island Exploration
You are assisting in a project to map a series of islands connected by bridges. Each island can be represented as a node and each bridge as an edge between nodes. Given a set of islands and connections, your goal is to find out how many islands can be explored starting from a specific island.
Input format:
- The first line contains two integers n (1 <= n <= 1000) and m (0 <= m <= 2000), where n is the number of islands and m is the number of bridges.
- The next m lines each contain two integers x and y (1 <= x, y <= n), indicating a bridge between islands x and y.
- The last line contains an integer i (1 <= i <= n), the starting island.
Output format:
- Output a single integer that represents how many islands can be explored from island i.
Example:
Input:
3 2
1 2
2 3
1
Output:
3
Key concepts
graphsbfsexploration
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