Hollow Rectangle Pattern - Problem
Given the width and height of a rectangle, print a hollow rectangle pattern using asterisks (*) for the borders and spaces for the interior.
A hollow rectangle has asterisks only on the top row, bottom row, leftmost column, and rightmost column. All interior positions contain spaces.
Output Format: Print each row on a separate line. Each row should have exactly width characters (asterisks and spaces).
Input & Output
Example 1 — Basic Rectangle
$
Input:
width = 5, height = 3
›
Output:
*****
* *
*****
💡 Note:
Top row: all 5 asterisks. Middle row: asterisk + 3 spaces + asterisk. Bottom row: all 5 asterisks.
Example 2 — Single Column
$
Input:
width = 1, height = 4
›
Output:
*
*
*
*
💡 Note:
When width is 1, every position is a border position, so all rows contain a single asterisk.
Example 3 — Single Row
$
Input:
width = 6, height = 1
›
Output:
******
💡 Note:
When height is 1, there are no middle rows, so we have one complete border row.
Constraints
- 1 ≤ width ≤ 100
- 1 ≤ height ≤ 100
Visualization
Tap to expand
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code