Generate a Hollow Star Square
Problem statement
You are given an integer n. Build an n by n hollow square as a string array.
- Every border position contains
*. - Every interior position contains a space character.
Return the rows from top to bottom.
Function
buildHollowSquare(n: int) → String[]Examples
Example 1
n = 4return = ["****","* *","* *","****"]The first and last rows are all border characters. Each middle row has two border stars surrounding two interior spaces.
Example 2
n = 2return = ["**","**"]A square of side two has no interior positions, so both rows contain only stars.
Constraints
2 <= n <= 1000- The returned output contains exactly
n2characters.