Right-Aligned Star Triangle
Given a positive integer n, return a right-aligned star triangle with n rows. Row i contains n-i leading spaces followed by i consecutive stars. Preserve…
Given a positive integer n, return a right-aligned star triangle with n rows. Row i contains n-i leading spaces followed by i consecutive stars. Preserve leading spaces, 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. - Every output row has a visible width of n characters.
Example 1: input n = 4; output * ** *** ****. The star count grows from one to four while the leading-space count shrinks from three to zero.
Example 2: input n = 1; output *. The smallest right-aligned triangle is one row containing one star.
Category: Pattern Programs. Topic: pattern-programs. Difficulty: Easy. Patterns: math.