shlogg · Early preview
Md Ariful Haque @mah-shamim

Count Colored Cells With 2n^2 - 2n + 1 Formula

Count Total Number of Colored Cells: Use formula 2n^2 - 2n + 1 to calculate colored cells after n minutes. Each minute adds 4*(k-1) new cells, forming an arithmetic sequence.

2579. Count Total Number of Colored Cells
Difficulty: Medium
Topics: Math
There exists an infinitely large two-dimensional grid of uncolored unit cells. You are given a positive integer n, indicating that you must do the following routine for n minutes:

At the first minute, color any arbitrary unit cell blue.
Every minute thereafter, color blue every uncolored cell that touches a blue cell.

Below is a pictorial representation of the state of the grid after minutes 1, 2, and 3.
Return the number of colored cells at the end of n minutes.
Example 1:

Input: n = 1
Output: 1
Explanation: After 1...