A2Z Lesson

Log in
← Back to the A2Z sheet

Step 01 Beginner Problems — Patterns

Pattern 19 — Symmetric-Void Pattern

Easy

Two solid blocks of stars separated by a void that opens and then closes: the figure starts as one solid band of 2n stars, splits into two blocks that drift apart until only single stars remain at the edges, then comes back together. It is Pattern 12's 'two sides plus a gap' idea rendered in stars and mirrored top-to-bottom.

* * * * * * * * * *
* * * *     * * * *
* * *         * * *
* *             * *
*                 *
*                 *
* *             * *
* * *         * * *
* * * *     * * * *
* * * * * * * * * *
Output for n = 5

How to think about it

Think of each row as three parts across a fixed canvas of 2n slots: a left block of stars, a gap of blank slots, and a right block equal to the left. In the top half, row i (0-based) has n - i stars per side and a gap of 2i slots — the void widens by two each row as the blocks erode from the inside. The bottom half runs the same formulas in reverse: row i has i + 1 stars per side and a gap of 2(n - i - 1) slots. The middle two rows are identical (1 star, a gap of 2n - 2 slots, 1 star), and the first and last rows are the solid 2n-star band.

Code

The code builds rows as token lists — side stars, then gap placeholders (' ' tokens that keep slot widths uniform), then side stars again — and joins them. A first loop generates the opening half and a second loop the closing half; concatenating the two lists and printing them in order gives the full symmetric figure.

def pattern(n): lines = [] for i in range(n): side = ["*"] * (n - i) gap = [" "] * (2 * i) lines.append(" ".join(side + gap + side)) for i in range(n): side = ["*"] * (i + 1) gap = [" "] * (2 * (n - i - 1)) lines.append(" ".join(side + gap + side)) for line in lines: print(line)

Key points

  • Row anatomy: side stars + gap + side stars, always totalling 2n slots.
  • Top half row i: stars per side = n - i, gap = 2i. The bottom half mirrors it.
  • The two middle rows are identical — the void is widest there (2n - 2 slots).
  • Placeholder blank tokens keep both blocks aligned; raw space printing breaks the right block.
  • The figure is symmetric both horizontally and vertically — fold it either way to check.

Suggested questions

Pattern 20 — Symmetry Pattern The inverse journey: blocks start separated and grow toward each other.
Pattern 12 — Number Crown Pattern The same left + gap + right construction with numbers.
Pattern 21 — Hollow Rectangle Pattern Another figure defined by its border and a hollow interior.
Reverse an array ↗ Mirrored halves meeting in the middle — the same symmetry, in array form.

Source note: this lesson follows the structure of Striver's public A2Z DSA course (takeUforward). Each problem links to its original platform, and all problems and content belong to their respective owners — STUDY-BUDDY does not claim ownership of the sheet or its problems, and no permission beyond public linking is claimed.