Skip to main content
Back to problems
Leetcode
Medium
Math
Combinatorics
Count Total Number Of Colored Cells

Count how many cells are colored after expanding a symmetric diamond-like pattern for nn steps.

Acceptance 0%
Problem Statement

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 nn, determine the total number of colored cells after the growth has been applied nn 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 n representing the number of growth steps.

Output Format

  • Return the total number of colored cells after n steps.

Constraints

  • 1n1 \le n.
  • The answer fits in a 64-bit signed integer for typical interview-sized inputs.
Examples
Sample cases returned by the problem API.

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.

Guided hints
Editorial and discussion links
Concept map and variants
Sign in to unlock
Track your progress
Sign in to bookmark this problem, save notes, and manage its revision plan.