Sandglass Star Pattern
Given a positive integer n, return a centered sandglass made of stars. The top row has 2n - 1 stars. Each following row in the upper half adds one leading…
Given a positive integer n, return a centered sandglass made of stars. The top row has 2n - 1 stars. Each following row in the upper half adds one leading space and removes two stars until the single-star center. The lower half mirrors the upper half without repeating the center. The result has exactly 2n - 1 rows. Do not add trailing spaces. Join adjacent rows with one newline character and do not add a trailing newline.
- 1 ≤ n ≤ 10 - n is always a positive integer. - The center row appears exactly once.
Example 1: input n = 4; output ******* ***** *** * *** ***** *******. The figure narrows to one centered star, then expands symmetrically.
Example 2: input n = 1; output *. The upper and lower halves share the same single center row.
Category: Pattern Programs. Topic: pattern-programs. Difficulty: Easy. Patterns: math.