iOS Grid Infection (Flood Fill) Design
Goal
Build an iOS app that displays a 2D grid with two colors. When the user taps a cell, all 4-directionally adjacent cells in the same connected component as the tapped cell should be flood-filled in a single interaction.
Assumptions (to make the problem well-scoped)
-
The grid contains exactly two colors (e.g., Color A and Color B).
-
On tap at cell (r, c), we flood-fill the connected component of the tapped cell’s original color to the other color (toggle). Alternatively, if a current paint color is selected in UI, fill to that color; the algorithm and design remain the same.
-
Adjacency is 4-directional (up, down, left, right).
-
The app should handle large grids efficiently, avoid stack overflow, and support reset and undo.
Deliverables
Describe:
-
UI architecture (UIKit or SwiftUI) and view structure.
-
Data structures to represent the grid.
-
Flood-fill algorithm (iterative vs. recursive) with time/space complexity.
-
How to handle large grids efficiently and avoid stack overflow.
-
How to support reset and undo.