Trains the technique from
LeetCode 2579Count Total Number of Colored CellsThis is an original problem, written from a brief that listed the technique, the difficulty, the topics, the function shape and the input bounds — none of that problem's wording, examples, hints or editorials. The link is there so you can map your practice onto the standard set.
Same function shape, different story and different numbers.
An endless sheet of square cells starts blank. In the first minute a single cell is inked. In every minute after that, every blank cell sharing a side with an inked cell becomes inked as well.
Return how many cells are inked at the end of minute n.
Example 1
One cell after the first minute, its four side neighbours after the second for five in all, and the eight cells ringing those after the third for thirteen.
Example 2
A fourth minute adds the ring of twelve cells one step further out, bringing the total to twenty-five.
Example 3
After seven minutes the diamond reaches six steps from the middle in every direction.
The editor is preloaded with this. It matches the parent problem's shape, so a solution that works here transfers to a judge unchanged.
def colored_cells(n: int) -> int:public long coloredCells(int n)See the step-by-step animation, the intuition, and clean code in every language — free, no credit card.