Hollow Pyramid Pattern
Given a positive integer n, print a centered hollow pyramid with n rows. Each row i (1-indexed) follows these exact rules: 1. Leading spaces: print (n - i)…
Given a positive integer `n`, print a centered hollow pyramid with `n` rows. Each row `i` (1-indexed) follows these exact rules: 1. **Leading spaces**: print `(n - i)` spaces before any star on that row. 2. **Row content width**: each row spans `(2 * i - 1)` character positions. 3. **Star placement**: print a star at the first position and at the last position of the row content. Every position in between is a space. 4. **Single-star exception**: when `i = 1`, the row contains exactly one star. 5. **Base-row exception**: when `i = n`, the entire base row is filled with stars — all `(2*n - 1)` positions. Do **not** print trailing spaces after the last star on any row.
- `1 ≤ n ≤ 10` - `n` is a positive integer
Example 1: input n = 4; output * * * * * *******. Row 1: 3 leading spaces, one star. Row 2: 2 leading spaces, star, one interior space, star. Row 3: 1 leading space, star, three interior spaces, star. Row 4 (base): all 7 positions are stars.
Example 2: input n = 2; output * ***. Row 1: 1 leading space, single star. Row 2 (base): all 3 positions are stars.
Example 3: input n = 6; output * * * * * * * * * ***********. Row 1: 5 leading spaces, single star. Rows 2-5 each widen the interior gap by 2. Row 6 (base): 11 stars.
Category: Pattern Programs. Topic: pattern-programs. Difficulty: Medium. Patterns: math.