Foundations Loops through pattern printing

23. Symmetric Void

Medium

Given an integer n, return the pattern below as a list of strings, one string per row, top row first.

********
***  ***
**    **
*      *
*      *
**    **
***  ***
********

That is the pattern for n = 4. Every row is 2n characters wide: a block of stars, a gap of spaces, and a second block as big as the first. The top row has no gap. In each row below it, both blocks lose one star and the gap grows by two spaces, until row n has a single star at each end.

The bottom half repeats the top half in reverse order, so the pattern has 2n rows and the two middle rows are the same.

Example 1

Input: n = 3

Output:
******
**  **
*    *
*    *
**  **
******

Explanation: The gaps in the top half are 0, 2 and 4 spaces, and the bottom half repeats them in reverse.

Example 2

Input: n = 1

Output:
**
**

Example 3

Input: n = 4

Output:
********
***  ***
**    **
*      *
*      *
**    **
***  ***
********

Check your understanding

Work out the answer for this input before you write any code.

n = 2

Constraints

  • 1 ≤ n ≤ 100

Clarifying questions

What you would ask an interviewer before writing any code.

Hints

Interview follow-ups

Runs in your browser
Code
Runs in your browser for now · some things may not work as expectedLn 1, Col 1

Sign in to oneby7

Keep your progress, your streak and your code, on any device.

New here? This creates your account too.