Foundations Loops through pattern printing
21. Letter Pyramid
Given an integer n, return the pattern below as a list of strings, one string per row, top row first.
A
ABA
ABCBA
ABCDCBA
The picture shows n = 4. The pyramid has n rows. Row i, counting from 1 at the top, climbs from A up
to the i-th capital letter and comes back down to A, so the top row is a single A and the bottom row
climbs to the n-th letter. The highest letter of a row appears once, in the middle of the row.
Every row is centred over the bottom row, which starts at the left edge. The letters sit side by side, and
nothing comes after the last A.
Example 1
Input: n = 3
A ABA ABCBA
Explanation: The rows climb to A, B and C, after 2, 1 and 0 spaces. Each row ends at its last A.
Example 2
Input: n = 1
AExample 3
Input: n = 5
A ABA ABCBA ABCDCBA ABCDEDCBA
Check your understanding
Work out the answer for this input before you write any code.
Constraints
1 ≤ n ≤ 26
Clarifying questions
What you would ask an interviewer before writing any code.