String Builder Pattern with a List

Medium ⏱ 12 min 52% acceptance ★★★★★ 4.9
Write build_star_triangle(rows) that returns a multi-line string forming a left-aligned triangle of asterisks with rows rows (row i has i asterisks), built by appending each row to a list and joining with newlines at the end — the standard "string builder" pattern for avoiding repeated concatenation.

Examples

Example 1
Input
rows = 3
Output
'*\n**\n***'
Explanation

Row 1 has 1 star, row 2 has 2 stars, row 3 has 3 stars, joined by newlines.

Constraints

  • rows >= 1

Topics

StringsString Building

Companies

ZomatoSwiggy

Hints

Hint 1

Append each row (built with `'*' * i`) to a list.

Hint 2

Join the list with `'\n'.join(lines)` once, at the end.

Loading the Python runtime… Run executes your code and shows printed output; Submit checks your function against this problem's examples.