A2Z Lesson

Log in
← Back to the A2Z sheet

Step 01 Beginner Problems — Patterns

Pattern 14 — Increasing Letter Triangle Pattern

Easy

The growing triangle dressed in letters: row one is 'A', row two is 'A B', and each row restarts at A and runs one letter further than the row above. It maps the number logic of Pattern 3 onto characters using character codes.

A
A B
A B C
A B C D
A B C D E
Output for n = 5

How to think about it

Number the rows i = 0, 1, ..., n-1. Row i has i + 1 letters: A, B, C, ..., up to the (i+1)-th letter. The letter at column j is chr(ord('A') + j) — you add the column offset to A's character code and convert back. The row always restarts from A (the value depends on the column, not on any running state), and the last letter of row i is chr(ord('A') + i). For n up to 26 the letters stay inside A-Z; beyond that the classic pattern is not defined.

Code

A list comprehension generates chr(ord('A') + j) for j in range(i + 1) — the letters from A up to the row's last letter — and the row is printed joined by spaces. All the machinery of Pattern 3 carries over; only the token generator changed, from str(j + 1) to a character computation.

def pattern(n): for i in range(n): letters = [chr(ord("A") + j) for j in range(i + 1)] print(" ".join(letters))

Key points

  • Letter at column j: chr(ord('A') + j) — character arithmetic replaces number formatting.
  • Row i ends at the (i+1)-th letter and always restarts at A.
  • Same skeleton as Pattern 3: the outer loop sets the length, the inner generates from the column.
  • Defined for n <= 26; beyond Z the alphabet runs out.
  • In C++ or Java the same trick is char('A' + j) — the idea is portable across languages.

Suggested questions

Pattern 15 — Reverse Letter Triangle Pattern The shrinking letter triangle — rows lose their last letter one by one.
Pattern 16 — Alpha-Ramp Pattern Each row repeats its own letter instead of running A, B, C...
Pattern 3 — Right-Angled Number Pyramid The numeric original of this pattern — same shape, digit tokens.
Reverse a String I ↗ More character-by-character work: walking a string position by position.

Source note: this lesson follows the structure of Striver's public A2Z DSA course (takeUforward). Each problem links to its original platform, and all problems and content belong to their respective owners — STUDY-BUDDY does not claim ownership of the sheet or its problems, and no permission beyond public linking is claimed.