Inverted Star Pyramid

Given a positive integer n, return a centered inverted star pyramid with n rows. Row i has i-1 leading spaces followed by 2(n-i)+1 consecutive stars. Preserve…

Given a positive integer n, return a centered inverted star pyramid with n rows. Row i has i-1 leading spaces followed by 2(n-i)+1 consecutive stars. Preserve leading spaces, add no trailing spaces, join rows with one newline, and add no trailing newline.

- 1 ≤ n ≤ 10 - n is always a positive integer. - The output contains exactly n rows.

Example 1: input n = 4; output ******* ***** *** *. Star widths shrink 7, 5, 3, 1 while leading padding grows 0, 1, 2, 3.

Example 2: input n = 1; output *. The smallest inverted pyramid is one centered star.

Category: Pattern Programs. Topic: pattern-programs. Difficulty: Easy. Patterns: math.