Skip to content
Onsite

Hollow Square Star Pattern

EasyP3Coding

Return an n x n hollow square as n lines. A cell is * when it is in the first row, last row, first column or last column, and a blank otherwise. The n cells of a row are joined with a single space, and trailing spaces are removed.

For n = 4 the rows are * * * *, * *, * *, * * * *.

Example 1

Input
n = 4
Output
["* * * *","* *","* *","* * * *"]

Example 2

Input
n = 1
Output
["*"]

Example 3

Input
n = 2
Output
["* *","* *"]

Constraints

  • 1 <= n <= 50

Hints

Run checks the 3 visible tests, Submit all 8.