Foundations Loops through pattern printing
13. Star Diamond
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. The rows grow by two stars at a time until the middle row, which holds
2n − 1 stars, and then shrink the same way back to a single star. The middle row appears once, so the
diamond has 2n − 1 rows in all. Every row is centred on the same column.
The stars in a row sit side by side. A row ends at its last star, with no spaces after it.
Example 1
Input: n = 3
* *** ***** *** *
Explanation: Five rows, with 1, 3, 5, 3 and 1 stars, each centred on the third column.
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.