Count Total Number of Colored Cells
Real-world version: Cells Inked After n MinutesThe statement here is our own: the same inputs, outputs and technique.
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.
Examples
Example 1
- Input
- n = 3
- Output
- 13
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
- Input
- n = 4
- Output
- 25
A fourth minute adds the ring of twelve cells one step further out, bringing the total to twenty-five.
Example 3
- Input
- n = 7
- Output
- 85
After seven minutes the diamond reaches six steps from the middle in every direction.
Constraints
- 1 <= n <= 10^5
The signature
The editor starts with this. It matches the parent problem's shape, so a solution that works here works on a standard judge unchanged.
def colored_cells(n: int) -> int:public long coloredCells(int n)Checking your plan…
How this problem was checked
- Passed: Reference solution run against 15 test cases: 15 passed
- Passed: 3 worked examples confirmed by running the code
- Passed: 0 eight-word sequences shared with the parent problem's text
- Passed: Agrees with an independent brute-force solution on random inputs
- Passed: Test set shown to catch deliberately broken solutions
- Passed: Reviewed by a separate quality pass
- Passed: Function arity matches the parent problem's