DSA interview question
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
vector<string> letterTriangle(int n); // row i: the first i letters of the alphabet
Input n | Output rows | Explanation |
|---|---|---|
| 1 | "A" | |
| 3 | "A", "AB", "ABC" | Row i has letters A through the i-th letter |
| 5 | "A", "AB", "ABC", "ABCD", "ABCDE" | |
| 26 | last row is the full alphabet A..Z | Largest valid n |
(Confirm: 1 ≤ n ≤ 26; letters are printed without separators.)
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 interviewAll 474 dsa interview questions
DSA mock interviews · System design interview questions · Free mock interview practice · Browse interviewers · Sign in