The hollow alphabet pyramid draws only the outline of a pyramid, writing each row’s letter on its two edges: A at the top, then B B, C C, D D, and a full base of E.
Quick answer: Treat row i as n + i β 1 positions. Print the row letter 'A' + i β 1 at the two edges, positions n β i + 1 and n + i β 1, and on every position of the last row. Everything else is a space.
This program is part of the Pyramid Patterns collection.
Table of contents8 sections
Hollow Alphabet Pyramid output
Output (n = 5):
A B B C C D D EEEEEEEEE

Same shape, other characters: the Hollow Number Pyramid and Hollow Pyramid Star Pattern programs draw this same outline with different characters. Putting them side by side shows which part of the loop decides the shape and which part decides what is printed.
How the hollow alphabet pyramid works
The outline is the same as in the hollow pyramid star pattern. Row i of a pyramid runs from column n β i + 1 to n + i β 1, and only those two ends are printed, except on the base, which closes the shape. Using the row letter instead of a star makes it easy to see which row each part of the outline belongs to.
- Run the outer loop for
ifrom1ton, one row per pass. - Go through
n + i β 1positions in the row. Print letters (letter numberi) wherej > n β i and (i = n or j = n β i + 1 or j = n + i β 1); print spaces everywhere else. - Move to the next line.
Key takeaways
- Only the two edges and the base are printed.
- The letter depends on the row: A on row 1, E on row 5.
j > n β ikeeps the leading spaces out of the test.- It is the letter version of the hollow number pyramid.
Hollow Alphabet Pyramid in C
#include <stdio.h>
int main(void) {
int n = 5;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n + i - 1; j++) {
if (j > n - i && (i == n || j == n - i + 1 || j == n + i - 1))
printf("%c", 'A' + i - 1);
else
printf(" ");
}
printf("\n");
}
return 0;
}Hollow Alphabet Pyramid in C++
#include <iostream>
using namespace std;
int main() {
int n = 5;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n + i - 1; j++) {
if (j > n - i && (i == n || j == n - i + 1 || j == n + i - 1))
cout << char('A' + i - 1);
else
cout << " ";
}
cout << endl;
}
return 0;
}Hollow Alphabet Pyramid in Java
public class HollowAlphabetPyramid {
public static void main(String[] args) {
int n = 5;
for (int i = 1; i <= n; i++) {
for (int j = 1; j <= n + i - 1; j++) {
if (j > n - i && (i == n || j == n - i + 1 || j == n + i - 1))
System.out.print((char) ('A' + i - 1));
else
System.out.print(" ");
}
System.out.println();
}
}
}Hollow Alphabet Pyramid in Python
n = 5
for i in range(1, n + 1):
for j in range(1, n + i):
if j > n - i and (i == n or j == n - i + 1 or j == n + i - 1):
print(chr(ord('A') + i - 1), end="")
else:
print(" ", end="")
print()Time and space complexity
The program prints one character for each position in the pattern, so for n rows it runs in O(nΒ²) time. It only needs a few loop variables, so the extra memory is O(1).
Frequently asked questions
How do I spell out the base as ABCDEFGHI?
On the last row print 'A' + j β 1 instead of the row letter. The edges keep their row letters.
Why is the second row not hollow?
It has only three positions and the outer two are edges, so the gap is a single space. The gap grows by two each row after that.
Can I use lowercase letters?
Yes. Start from 'a' instead of 'A'.
How do I make it a hollow alphabet diamond?
Print this pattern, then the same rows from n β 1 back to 1 without filling the last row. The edges then close in a point at the bottom.






