You are given an m x n binary grid representing water
(
0) and land
(
-
laid out on a torus: the top edge is adjacent to the bottom edge and the left edge is adjacent to the right edge. Two land cells are connected if they share a side (4-directional), considering wrap-around adjacency. Return the number of connected land components (islands). Follow-ups:
(
-
Provide two distinct approaches (e.g., graph search and disjoint-set).
(
-
Analyze the time and space complexities.
(
-
Extend the solution to support a stream of single-cell flips between 0 and 1 and report the island count after each update.