Archipelago Explorer - Problem
An explorer is on island 0 in an archipelago of n islands numbered 0 to n - 1.
You are given a 2D array bridges where bridges[i] = [u, v] means a two-way bridge connects island u and island v.
Return the total number of islands the explorer can visit (including island 0).
Input & Output
Example 1
$
Input:
n=7, bridges=[[0,1],[0,2],[1,3],[4,5],[5,6]]
›
Output:
4
💡 Note:
Islands 0,1,2,3 reachable. 4,5,6 disconnected.
Example 2
$
Input:
n=4, bridges=[[0,1],[1,2],[2,3]]
›
Output:
4
💡 Note:
All reachable via chain.
Example 3
$
Input:
n=5, bridges=[]
›
Output:
1
💡 Note:
No bridges. Only island 0.
Constraints
- 1 <= n <= 2*10^5
- 0 <= bridges.length <= 2*10^5
- 0 <= u, v < n
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code