Practice/fresherHollow Square
⏱ 00:00
Best: 0/100
Boundary ConditionsTarget Time: 10 mins

Hollow Square

Given an integer N, print a hollow square of size N x N where the perimeter consists of stars (*) and the interior consists of spaces.

Input Format
A single integer N.
Output Format
Print N rows forming a hollow square.
Constraints:1 <= N <= 20
Concepts Required:
Boundary checking (i == 1 || i == N || j == 1 || j == N)Conditional output within grid
Expected Pattern PreviewASCII Monospace
*****
*   *
*   *
*   *
*****

Notice how character spacing and row counts scale systematically based on the input N.

Concrete Examples

Example 1
Input:
5
Output:
*****
*   *
*   *
*   *
*****

Explanation: Top and bottom rows are solid stars. Middle rows have star on boundary and spaces inside.

← Back to All Challenges