Implement tap-to-infect color grid on iOS
PinterestSoftware Engineer · OnsiteLast updated
This question evaluates proficiency in mobile UI architecture, grid data structures, connected-component algorithm reasoning, and state management concerns such as undo and memory/stack safety within the mobile app development and iOS domain.
Implement an iOS app that displays a 2D grid of cells colored with two colors. When the user taps a cell, all 4-directionally adjacent cells of the same original color should be "infected" and change to the tapped color in a single interaction. Describe your UI architecture (UIKit or SwiftUI), data structures to represent the grid, and the flood-fill algorithm (iterative vs. recursive) with time/space complexity. Handle large grids efficiently, avoid stack overflow, and support reset/undo.
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.