TikTok·Software Engineer·Technical Phone Screen
- Given an m x n binary grid on a torus (top wraps to bottom, left wraps to right), count the number of connected land components (islands) using 4-directional adjacency with wrap-around.
- Solve the same torus island problem using two different approaches, such as graph search and a disjoint-set (union-find) structure.
- What are the time and space complexities of your solutions?
- Extend your solution to handle a stream of single-cell flip updates (toggling between land and water) and report the island count after each update.
“I started with standard BFS island counting and felt pretty good about it, then the wrap-around adjacency hit me.”