Explanation

527.Print a Hollow Square Star Pattern

Easy
Given n, return an n × n square drawn with stars on its border and spaces inside. Hollow shapes introduce conditional printingConditional PrintingDeciding, for each position, whether to print a star or a space based on a condition.: instead of printing the same character in every cell, each cell asks "am I on the edge?". The first solution asks that question cell by cell; the second notices that there are only two distinct rows and builds each just once.

Example 1:

Input: n = 4

Output: ["****","* *","* *","****"]

Example 2:

Input: n = 2

Output: ["**","**"]

+ 4 hidden test cases run on Submit.

Constraints:

  • ●1 ≤ n ≤ 20

n =

4