740. Print Pattern — Inverted Triangle (Recursive)

EasyRecursionRecursion

Given a positive integer n, return a string representing an INVERTED right-angle triangle built from * characters with n rows. Row 1 contains n stars, row 2 contains n-1 stars, ..., and the last row contains exactly 1 star. Rows are joined by the literal two-character sequence \n so the output is a single line in the test format. Build the string recursively, no loops.

Input: A single positive integer n.

Output: Return a string of n rows joined by '\n'.

Examples

Example 1
Input: 3
Output: ***\n**\n*
Explanation: Three rows of decreasing length.
Example 2
Input: 1
Output: *
Explanation: Single star.
Example 3
Input: 4
Output: ****\n***\n**\n*
Explanation: Four rows: 4, 3, 2, 1 stars.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →