Skip to content

2579. Count Total Number of Colored Cells #1393

Answered by mah-shamim
mah-shamim asked this question in Q&A
Discussion options

You must be logged in to vote

We need to determine the number of colored cells in an infinitely large two-dimensional grid after n minutes, where each minute colors all uncolored cells adjacent to already colored cells.

Approach

The key observation here is that the number of colored cells follows a specific pattern. Let's analyze the expansion of colored cells over time:

  • At n = 1, there is 1 colored cell.
  • At n = 2, the initial cell plus its four immediate neighbors (up, down, left, right) form a 3x3 square, resulting in 5 colored cells.
  • At n = 3, the colored cells expand further outward, forming a diamond shape with an additional layer of cells around the previous square.

By examining the pattern, we notice that eac…

Replies: 1 comment 2 replies

Comment options

mah-shamim
Mar 5, 2025
Maintainer Author

You must be logged in to vote
2 replies
@kovatz
Comment options

kovatz Mar 5, 2025
Collaborator

@mah-shamim
Comment options

mah-shamim Mar 5, 2025
Maintainer Author

Answer selected by kovatz
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
question Further information is requested medium Difficulty
2 participants