A reverse fixed-start alphabet triangle always begins each row at the same top letter and counts down, while the stopping letter rises so the reverse tail gets shorter.
Remember
Rule: for stop letter i from A to last,
print last down through i
EDCBA
EDCB
EDC
ED
E ← 5 rows (left edge fixed at E)
Same widths as Program 7 (5, 4, 3, 2, 1), but Program 7 moves the left edge (EDCBA, DCBA, …). Here the left edge stays put. Compare also with Program 5, which shrinks forward prefixes from A.
Approach
How to Solve It
Two ways to emit the same shape — start with nested charCodeAt loops, then optionally reverse a prefix once and take shorter leading slices.
Method
Idea
Best for
Nested charCode loops
Outer = rising stop; inner = top..stop downward
Learning, interviews, exams
Reverse + slice(0, len)
Build EDCBA… once, take shorter prefixes
Shorter demos once loops click
Pseudocode
Pseudocode
base = code of 'A'
top = base + rows - 1
for stop from base to top:
line = ""
for code from top down to stop:
append fromCharCode(code) to line
print line
Cheat sheet
Goal
Pattern
Raise stop code
for (let stop = base; stop <= top; stop++)
Print top..stop reverse
for (let code = top; code >= stop; code--) line += String.fromCharCode(code);
End the row
console.log(line);
Top code from rows
const top = "A".charCodeAt(0) + rows - 1;
One-line row shortcut
Reverse the A…top prefix, then slice(0, len) while len shrinks
Append letters without a newline, then end the row once.
Try it
Live Preview
Change the row count and the reverse fixed-start triangle updates instantly — capped at 26 letters (A–Z).
Whole numbers from 1 to 26. Tap a chip or type a value — the preview redraws as you go.
Live result5 rows · 15 letters
EDCBA
EDCB
EDC
ED
E
Trace
Worked Walkthrough — rows = 4
Trace each outer-loop stop as stop rises from A to D with top fixed at D.
Stop
Inner codes
Printed row
Letters
A
D..A
DCBA
4
B
D..B
DCB
3
C
D..C
DC
2
D
D..D
D
1
Total letter prints: 4 + 3 + 2 + 1 = 10 = 4×5/2 — same triangular count as Programs 5 and 7.
Code
JavaScript Programs
Three complete programs: fixed top letter, prompt input, and a reverse-slice shortcut. Use View Output for sample results, or Try It Yourself to edit and run in the playground.
Example 1 — Fixed top at E
Hard-coded top — every row starts at E; the stop letter rises to shorten the tail.
JavaScript
const base = "A".charCodeAt(0);
const top = "E".charCodeAt(0);
for (let stop = base; stop <= top; stop++) {
let line = "";
for (let code = top; code >= stop; code--) {
line += String.fromCharCode(code);
}
console.log(line);
}
1. Outer loop raises the stop.stop runs from A to E — longest row first.
2. Inner loop always starts at E. For each stop, code runs from top down to stop, so the row is E…stop in reverse.
3. Print letters, then break the line.line += stays on the row; console.log(line) after the inner loop starts the next (shorter) row.
When stop is A you get EDCBA; when it is E you get E.
Example 2 — User Input Version
Read the row count at runtime with prompt. Validate with parseInt and clamp to 26 for A–Z demos.
JavaScript
let rows = parseInt(prompt("Enter the number of rows:"), 10);
const base = "A".charCodeAt(0);
if (!Number.isFinite(rows) || rows < 1) {
console.log("Please enter a whole number of rows >= 1.");
} else {
if (rows > 26) rows = 26;
const top = base + rows - 1;
for (let stop = base; stop <= top; stop++) {
let line = "";
for (let code = top; code >= stop; code--) {
line += String.fromCharCode(code);
}
console.log(line);
}
}
1. Take and reverse the prefix.ABCDE reversed becomes EDCBA — the first printed row.
2. Shrink the leading slice.slice(0, 5) is the full row; slice(0, 4) drops the trailing A; and so on down to E.
3. Learn loops first. Use Examples 1–2 when you need to show nested bounds; treat this as a polish shortcut afterward.
Edge Cases & Pitfalls
Check these before calling the solution done.
code = stop
Program 7 by mistake
If the inner loop starts at stop instead of top, you print EDCBA, DCBA, … Use for (let code = top; code >= stop; code--).
code >= base
No shrinking
Stopping at A every time reprints the full reverse run. The stop must be the rising outer variable.
log inside
Column of letters
If console.log is inside the inner loop, each letter lands on its own line. Append with +=; call console.log only after the inner loop.
rows > 26
Past Z
Codes leave A–Z when rows > 26. Clamp or reject in interactive programs.
rows = 1
Single A
Output is just A — top and stop coincide. A good sanity check.
Bad prompt
Use Number.isFinite
Bare parseInt(prompt()) yields NaN on letters — validate before the outer loop.
Analysis
Time and Space Complexity
Program
Time
Extra space
Nested loops (Examples 1–2)
O(rows²)
O(n) for the current line string
Reverse + slice (Example 3)
O(rows²)
O(n) for the reversed prefix and temporary row strings
Total letters = n + (n - 1) + … + 1 = n(n + 1)/2 — quadratic in n. Same totals as Programs 5 and 7.
Remember
Key Takeaways
Rule: always start at the top letter; raise the stop so each reverse row shortens.
vs Program 7: same widths — here the left edge stays fixed; there the left edge moves.
Break the row: call console.log only after the inner loop.
Complexity:O(n²) time from the triangular letter count.
One line: for stop from A to the top letter, append top down through stop, then console.log.
Frequently Asked Questions
Because the inner loop always starts at the top letter (E in the 5-row example) and counts down. So the first printed character each row is always E.
The outer loop increases the stopping point for the inner loop. That shortens the tail each row, producing EDCBA, then EDCB, then EDC, and so on.
Program 7 changes the first letter each row (E, then D, then C…). Program 8 keeps the first letter fixed and only shortens the reverse tail.
Program 5 prints forward prefixes from A (ABCDE, ABCD, …). This pattern prints reverse prefixes from a fixed top (EDCBA, EDCB, …). Same shrinking widths; opposite letter direction and left edge.
Every row would print the full reverse run (EDCBA each time) with no shrinking.
line += stays on the same line. console.log ends the current line. Letters use +=; the row break uses console.log after the inner loop.
O(n²) for n rows, because total printed characters are n(n+1)/2.
Use parseInt(prompt(...), 10), check Number.isFinite(rows), and clamp between 1 and 26 so letter codes stay within A–Z.
🤔
Did you know?
Every row begins with the same top letter because the inner loop always starts there. The outer loop only raises the stopping point, so the tail shortens: EDCBA, EDCB, EDC, ED, E. Same widths as Program 7, but the left edge stays fixed.