739. Print Pattern — Right Angle Triangle (Recursive)

EasyRecursionRecursion

Given a positive integer n, return a string representing a right-angle triangle built from * characters with n rows. Row i (1-indexed) contains exactly i asterisks. Rows are joined by the literal two-character sequence \n (a backslash followed by an n) so the output is a single line in the test format. Build the string recursively without loops.

Input: A single positive integer n.

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

Examples

Example 1
Input: 3
Output: *\n**\n***
Explanation: Three rows: '*', '**', '***'.
Example 2
Input: 1
Output: *
Explanation: Just one star.
Example 3
Input: 2
Output: *\n**
Explanation: Two rows.

Constraints

Asked by

TCSInfosysWiproCognizantCapgemini
Solve this problem in the editor →