Shape Rule
Right-aligned sequence
Growing rows of continuous letters sit on the right.

Print letters in a running sequence (A, then B C, then D E F…) while keeping the triangle right-aligned by printing empty 2-column cells first. View output in a monospace terminal because alignment relies on fixed-width cells. Compare Program 13 (sequential, left-aligned) and Program 20 (right-aligned reverse). Includes a live preview, worked JavaScript examples, edge cases, and complexity.
Right-aligned sequence
Growing rows of continuous letters sit on the right.
Never reset
k += 1 only when a letter prints — A…O across 5 rows.
Width 2
Pad with " "; append letters with String.fromCharCode(k).padStart(2, " ").
j > i
Empty cells first, then letters for right alignment.
1–6 rows
Pick a height (max 6 keeps letters within A–U).
Complexity
n rows × n cells per fixed-width scan.
A right-aligned sequential alphabet pyramid prints a continuous stream of letters into a right-aligned triangle, using fixed-width cells so empty pads and letters share the same column size.
In JavaScript you solve it with nested loops, a running counter (charCodeAt/fromCharCode), and matching pad/letter widths (" " vs ch.padStart(2, " ")).
It combines continuous counters, right alignment, and format-width printing — three skills that show up often in console layout labs.
k never resets between rows.
Empty cells print before letters.
" " matches ch.padStart(2, " ").
Alignment needs a fixed-width font.
In short: for each row i, scan n cells - append " " while j > i, otherwise append the next letter with padStart(2, " "), then call console.log(line).
Given a row count n (or fixed 5), print a right-aligned pyramid of continuous alphabet letters in 2-column cells.
// Five rows (monospace; each cell is width 2)
// A
// B C
// D E F
// G H I J
// K L M N O | Item | Type | Description |
|---|---|---|
n | int | Number of rows. Letter count = n(n+1)/2 (15 for n=5). |
| Printed output | text | Right-aligned continuous letters in fixed-width cells. |
k = "A".charCodeAt(0)
for i in 1..n:
line = ""
for j from n down to 1:
if j > i: line += " "
else: line += String.fromCharCode(k++).padStart(2, " ")
console.log(line) | Approach | Idea | Best for |
|---|---|---|
| Fixed-width scan | Pad or letter in each of n cells | Matching this classic sample |
| Explicit pad + letters | Print pads, then i letters via k++ | Clearer reading / teaching rewrite |
| Goal | Pattern |
|---|---|
| Counter | k = "A".charCodeAt(0) (outside outer loop) |
| Rows | for (let i = 1; i <= n; i++) |
| Scan cells | for (let j = n; j >= 1; j--) |
| Pad cell | line += " " when j > i |
| Letter cell | line += String.fromCharCode(k++).padStart(2, " ") |
| Left-aligned sequence | See Program 13 |
Same fixed-width row — different roles on each cell.
pad2-column empty cell for right alignment
letterNext sequential letter in a width-2 field
streamContinues A, B, C… across every row
breakEnds the row after n cells
Reach for this when teaching continuous counters with fixed-width alignment.
Keep the running counter; add right alignment with width-2 cells.
Practice ch.padStart(2, " ") matching pad width exactly.
Same right-align idea; sequential fill vs reverse suffixes.
Show why proportional fonts break column alignment.
This is a console teaching pattern — not how you build modern app screens.
Key benefit: matching pad and letter widths turns a continuous alphabet stream into a clean right-aligned pyramid.
Choose between 1 and 6 rows and draw the right-aligned sequential pyramid in the browser (monospace cells).
Three complete JavaScript programs - fixed 5 rows, user-chosen row count, and an explicit pad-then-letters rewrite. Click View Output to reveal sample console results, or Try it Yourself to run in the browser editor.
Print five right-aligned sequential rows with a running counter.
A single counter k increments only when a letter is appended, and padStart(2, " ") keeps columns aligned.
let k = "A".charCodeAt(0);
for (let i = 1; i <= 5; i++) {
let line = "";
for (let j = 5; j >= 1; j--) {
if (j > i) {
line += " ";
} else {
line += String.fromCharCode(k++).padStart(2, " ");
}
}
console.log(line);
} When i = 3, two cells append " " and three cells append D, E, F via k++. Because k is outside the outer loop, the next row continues at G.
Let the user choose how many rows to print.
Note: for large values, letters will go past Z. Validate parseInt(prompt()) with Number.isFinite and a letter-budget cap in real apps.
let n = parseInt(prompt("Enter number of rows (like 5):"), 10);
if (!Number.isFinite(n)) {
console.log("Please enter a whole number.");
} else {
n = Math.max(1, Math.min(n, 6));
let k = "A".charCodeAt(0);
for (let i = 1; i <= n; i++) {
let line = "";
for (let j = n; j >= 1; j--) {
if (j > i) {
line += " ";
} else {
line += String.fromCharCode(k++).padStart(2, " ");
}
}
console.log(line);
}
} Same pad/letter rules; only the shared width follows n. Letter count is n(n+1)/2 - cap so it stays ≤ 26 for A–Z only.
Same shape with separate pad and letter loops.
Often clearer to read: append n - i empty cells, then i sequential letters.
const n = 5;
let k = "A".charCodeAt(0);
for (let i = 1; i <= n; i++) {
let line = "";
for (let s = 0; s < n - i; s++) {
line += " ";
}
for (let L = 0; L < i; L++) {
line += String.fromCharCode(k++).padStart(2, " ");
}
console.log(line);
} Row i needs n - i pad cells and i letters from the continuous counter. Same visual pyramid as the single-scan version - only the loop structure changes.
k = "A".charCodeAt(0)A single running counter that never resets between rows.
The inner scan runs from n down to 1. When j > i we append two spaces to keep the same cell width as a letter.
We print letters using ch.padStart(2, " "), so each letter occupies 2 columns and lines up with the padding.
console.log(line) ends the row so the next row continues the same k.
Because k increments only when we print a letter, the alphabet continues across rows — O(n²) time.
Trace each row’s pads, letters, and the running counter range.
i | Pad cells | Letters | Printed row |
|---|---|---|---|
1 | 4 | A | ········A |
2 | 3 | B C | ······B C |
3 | 2 | D E F | ····D E F |
4 | 1 | G H I J | ··G H I J |
5 | 0 | K L M N O | K L M N O |
Total letters: 1+2+3+4+5 = 15 (A through O). Each cell is 2 columns wide.
Where this sequential right-aligned pyramid shows up beyond the homework prompt.
Clearest demo of a counter that never resets across rows.
Example: reset k once and compare to Program 1-style prefixes.
Same sequence — left-aligned vs right-aligned layout.
Example: print both for n = 5 side by side.
Match pad string length to ch.padStart(2, " ") field width.
Example: try one-space pads and watch columns break.
Teach pad count separately from letter count (Example 3).
Example: compare scan vs pad+letters outputs.
Triangular letter counts make O(n²) easy to see.
Example: 5 rows print 15 letters (plus pad cells).
Practice capping n so n(n+1)/2 stays ≤ 26.
Example: n=7 needs 28 letters — past Z.
Pro Tip: say “empty cells first, then keep counting letters” before coding — that story prevents resetting k or mismatched widths.
Why this pattern earns a spot after left-aligned sequential triangles.
Mismatched pad width or a reset counter shows up immediately.
Fixed-width scan or explicit pad/letter loops teach the same shape.
A natural place to learn JavaScript string formatting with ch.padStart(2, " ").
Streaming output needs no storage beyond loop variables.
Pro Tip: learn the classic scan version first; treat the explicit pad/letter rewrite as a clarity upgrade afterward.
Small habits that keep right-aligned sequential pyramids clean.
Do not reset the counter each row if you want continuous letters.
Use two spaces when letters use ch.padStart(2, " ").
Number.isFiniteAvoid crashes when the user types letters instead of a number.
Keep n(n+1)/2 ≤ 26 for A–Z-only output.
Proportional fonts make width-2 cells look misaligned.
Pro Tip: if every row starts with A, you almost certainly reset k inside the outer loop.
Mistakes that commonly break right-aligned sequential pyramids.
Each row starts at A again — that is a different pattern.
→ Keep k outside the outer loop.
Empty cells become narrower than ch.padStart(2, " ") letter fields.
→ Append " " (two spaces) for each pad cell.
Columns look broken even when the code is correct.
→ View output in a monospace terminal/font.
Letters or empty input throw FormatException.
→ Validate parseInt(prompt()) with Number.isFinite and re-prompt on failure.
Large n needs more than 26 letters.
→ Cap n so n(n+1)/2 ≤ 26, or define wrap/stop policy.
Check these inputs before calling the solution done.
Output is just A (no pads).
15 letters through O.
Through F (Example 2).
Needs 28 letters — decide wrap/stop policy.
parseInt(prompt()) yields NaN — use Number.isFinite.
Same loops with k = "a".charCodeAt(0).
Try these variations to lock in the pattern.
k = "A".charCodeAt(0) each row once" " ↔ ch.padStart(2, " ")).Quick Takeaway: pad empty width-2 cells first, print the next letters with matching width, keep counting across rows, then break the line.
| Program | Time | Extra space |
|---|---|---|
| Fixed-width scan (Examples 1–2) | O(n²) | O(1) |
| Explicit pad + letters (Example 3) | O(n²) | O(1) |
Each of n rows scans n cells (or pads + letters totaling n), so total work is O(n²).
The right-aligned sequential alphabet pyramid is a small nested-loop exercise with lasting payoff: a continuous letter counter, fixed-width cells, and leading empty cells for alignment. Master the classic A…O sample, then try user input and the explicit pad rewrite.
Practice the three examples above, then continue to Program 23’s right-aligned reverse alphabet pyramid.
Keep k outside, match pad and letter widths, print empty cells while j > i, then advance letters and break the line.
parseInt(prompt()) with Number.isFinite and cap the letter budgetk each row for this patternconsole.log(line) inside the cell loopPrint the right-aligned sequential pyramid the beginner-friendly way.
Pad + continuous letters
DefinitionNever reset
Code" " & {0,2}
CodeEnds each scan
I/OO(n²) time
AnalysisEach slot is 2 columns wide. Padding uses " " and letters use ch.padStart(2, " ") so columns line up in monospace output. The counter never resets, so letters run continuously from A to O for 5 rows.
Next up: right-aligned reverse alphabet pyramids (E, E D, E D C, …).
12 people found this page helpful