DSA problem
Sandglass (Hourglass) Pattern
Given an integer N, print a sandglass (hourglass) pattern of stars - an inverted pyramid stacked on top of a regular pyramid.
The sandglass is the inverse of a diamond. Where a diamond expands then contracts, a sandglass contracts then expands. The upper half is an inverted pyramid that starts wide and narrows to a single star, and the lower half is a regular pyramid that starts narrow and widens back out.
This reinforces that complex-looking patterns are just combinations of simpler ones: identify the sub-patterns and you can build anything.
Examples
Example 1
Input:
N = 5Output:
*********
*******
*****
***
*
***
*****
*******
*********Explanation: Rows narrow to a single middle star, then widen back out symmetrically.
Constraints
- 1 <= N <= 100
3 hints and a full solution walkthrough with step-by-step visualizations are available in the practice editor.