Foundations Loops through pattern printing
24. Symmetric Butterfly
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 has a block of stars, a wing, at each edge, with a gap of spaces
between them. The wings grow by one star per row and the gap closes by two spaces, until the middle row is
2n stars. Below the middle row, the rows above it repeat in reverse order.
The middle row appears once, so the butterfly has 2n − 1 rows. Every row is exactly 2n characters wide
and starts and ends with a star.
Example 1
Input: n = 3
* * ** ** ****** ** ** * *
Explanation: The wings hold 1, 2, 3, 2 and 1 stars, and every row is 6 characters wide.
Example 2
Input: n = 1
**Example 3
Input: n = 5
* * ** ** *** *** **** **** ********** **** **** *** *** ** ** * *
Check your understanding
Work out the answer for this input before you write any code.
Constraints
1 ≤ n ≤ 100
Clarifying questions
What you would ask an interviewer before writing any code.