PPractick

DSA interview question

Pattern 14: Increasing Letter Triangle

Easy · Algorithms · Topics: pattern building

The problem

The first letter pattern: row 1 is A, row 2 is AB, row 3 is ABC, and so on. The shape is the familiar right triangle; what's new is producing letters from a position. In C++ a char is a small integer, so 'A' + k is the k-th letter after A. This character arithmetic is used constantly in string problems (frequency arrays, Caesar ciphers, mapping letters to indices), which is why this simple pattern is worth getting exactly right.

Example for n = 4:

A
AB
ABC
ABCD

Function signature

vector<string> letterTriangle(int n);  // row i: the first i letters of the alphabet

Test cases

Input nOutput rowsExplanation
1"A"
3"A", "AB", "ABC"Row i has letters A through the i-th letter
5"A", "AB", "ABC", "ABCD", "ABCDE"
26last row is the full alphabet A..ZLargest valid n

(Confirm: 1 ≤ n ≤ 26; letters are printed without separators.)

How interviewers phrase it

Clarifying questions to ask

  1. Uppercase or lowercase?
  2. Is N at most 26?
  3. Separated by spaces or not?

Follow-ups to expect

  1. "How do you get the k-th letter?"
  2. "How do you go the other way, from a letter to its index?"
  3. "What happens if N is 27?"
  4. "What's the complexity?"

Practise questions like this with a real engineer

On Practick another engineer interviews you live for 60 minutes on a question from this bank. They have the full interviewer guide beside the call: the expected answer to every follow-up, hints to give if you stall, and a scoring rubric. You get the model solution once the session settles. It is free: interview someone for an hour and you have earned your own.

Book a free mock interview

Related questions

All 474 dsa interview questions

DSA mock interviews · System design interview questions · Free mock interview practice · Browse interviewers · Sign in