Count how many cells are colored after expanding a symmetric diamond-like pattern for steps.
You start with 1 colored cell in the first step. In each next step, the colored shape grows symmetrically by adding a new outer layer around the previous shape. For step , determine the total number of colored cells after the growth has been applied times.
The growth follows the standard pattern where the number of newly added cells increases by 4 every two steps, producing a centered diamond-like expansion.
Input Format
- A single integer
nrepresenting the number of growth steps.
Output Format
- Return the total number of colored cells after
nsteps.
Constraints
- .
- The answer fits in a 64-bit signed integer for typical interview-sized inputs.
Example 1
Input
n = 1
Output
1
Explanation
The first step colors only the center cell.
Example 2
Input
n = 2
Output
5
Explanation
The second step adds 4 surrounding cells, for a total of 1 + 4 = 5.
Show 1 more example
Example 3
Input
n = 3
Output
13
Explanation
The growth adds 8 more cells on the third step, giving 1 + 4 + 8 = 13.
Premium problem context
Unlock deeper context for this problem
Premium adds guided hints, editorial links, similar variants, discussion resources, and concept maps so you can understand why a problem matters, not just solve it once.