Back to Practice
#0214

Hollow Square Pattern

MediumPython25 min20 XP

Problem

Return an n by n hollow square pattern as a list of strings using "*" for border and spaces inside.

Why This Matters

Hollow patterns are useful because they force you to separate boundary cells from interior cells.

Function Signature

def hollow_square(n):

Examples

Example 1
Inputn = 4
Output["****", "* *", "* *", "****"]

Only the first row, last row, first column, and last column are stars.

Constraints

  • Return the exact requested value.
  • Handle small edge cases cleanly.
  • Prefer readable Python over clever shortcuts.
CodePython
Visible browser tests run here when available.
Testcases1 visible / 3 hidden categories
Core example
Inputn = 4
Expected["****", "* *", "* *", "****"]

Only the first row, last row, first column, and last column are stars.

Hidden Test Categories
n = 1n = 2n = 5