Right-Aligned Star Triangle

00:00
Easyloopsnested loopspatternsstring manipulation

Implement a function printTriangle that takes an integer n as input and returns a string representing a right-aligned upright triangle of asterisks.

The triangle should have n rows. The first row should contain one asterisk, and each subsequent row should have one more asterisk than the previous, with all rows right-aligned. Stars on the same row should be separated by a single space.

Constraints

  • 1 <= n <= 20

Examples

Input → 1
Output → *
Explanation:

For n=1, there is only one row with one asterisk, right-aligned (which means no leading spaces).

Input → 3
Output → * * * * * *
Explanation:

For n=3, the triangle has 3 rows. The first row has 1 star, the second 2, and the third 3, all right-aligned with spaces between stars.

Input → 5
Output → * * * * * * * * * * * * * * *
Explanation:

A standard 5-row right-aligned triangle, demonstrating the decreasing leading spaces and increasing stars per row.