A2Z Lesson

Log in
← Back to the A2Z sheet

Step 01 Beginner Problems — Patterns

Pattern 15 — Reverse Letter Triangle Pattern

Easy

The letter triangle of Pattern 14 draining away: the first row runs A through the n-th letter, and every row below drops the final letter, until only 'A' remains. It pairs Pattern 14's character generation with Pattern 6's shrinking count.

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

How to think about it

Number the rows i = 0, 1, ..., n-1. Row i has n - i letters: A, B, ..., up to the (n - i)-th letter. The letter at column j is still chr(ord('A') + j) — values come from the column exactly as in Pattern 14 — but the row length now follows the shrinking formula n - i instead of i + 1. Row 0 is the full run A..(n-th letter); the last row (i = n - 1) has length 1 and prints just A.

Code

The code generates letters for j in range(n - i) and joins them. Only the range bound differs from Pattern 14 — a one-token change that flips the triangle from growing to shrinking, which is precisely the lesson: the shape lives in the bounds.

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

Key points

  • Row i: length = n - i, letters A .. chr(ord('A') + n - i - 1).
  • Values still come from the column index; only the row length formula changed.
  • First row is the longest (n letters); the last row is the single letter A.
  • Patterns 14 and 15 together show i + 1 vs n - i driving identical inner logic.
  • The set of rows is the same as Pattern 14's, printed in reverse order.

Suggested questions

Pattern 14 — Increasing Letter Triangle Pattern The growing version — together they bracket the letter-triangle family.
Pattern 18 — Alpha-Triangle Pattern Letters again, but each row slides its starting letter down from the top of the range.
Pattern 6 — Inverted Numbered Right Pyramid The same n - i shrink with the numbers 1..n-i.
Palindrome Check ↗ Letter sequences and how they read forwards and backwards — a natural next string drill.

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.