Foundations Loops through pattern printing
22. Letter Triangle From the End
Easy
Given an integer n, return the pattern below as a list of strings, one string per row, top row first.
E
DE
CDE
BCDE
ABCDE
The picture shows n = 5. The top row holds only the n-th capital letter of the alphabet. Each row below it
adds the letter just before at its front, so the bottom row holds all n letters from A onwards.
The letters in a row sit side by side, with no spaces between them and none at either end.
Example 1
Input: n = 4
Output:
D CD BCD ABCD
Explanation: The fourth letter is D, so every row ends with D.
Example 2
Input: n = 1
Output:
AExample 3
Input: n = 26
Output:
Z YZ XYZ WXYZ VWXYZ UVWXYZ TUVWXYZ STUVWXYZ RSTUVWXYZ QRSTUVWXYZ PQRSTUVWXYZ OPQRSTUVWXYZ NOPQRSTUVWXYZ MNOPQRSTUVWXYZ LMNOPQRSTUVWXYZ KLMNOPQRSTUVWXYZ JKLMNOPQRSTUVWXYZ IJKLMNOPQRSTUVWXYZ HIJKLMNOPQRSTUVWXYZ GHIJKLMNOPQRSTUVWXYZ FGHIJKLMNOPQRSTUVWXYZ EFGHIJKLMNOPQRSTUVWXYZ DEFGHIJKLMNOPQRSTUVWXYZ CDEFGHIJKLMNOPQRSTUVWXYZ BCDEFGHIJKLMNOPQRSTUVWXYZ ABCDEFGHIJKLMNOPQRSTUVWXYZ
Check your understanding
Work out the answer for this input before you write any code.
n = 3
Constraints
1 ≤ n ≤ 26
Clarifying questions
What you would ask an interviewer before writing any code.