DSA interview question
This pattern keeps the triangle shape but changes what is printed once more: every entry in row i is the number i itself. So row 1 is 1, row 2 is 2 2, row 3 is 3 3 3. Placed next to Pattern 3, it shows exactly the difference between printing a value that depends on the column (1, 2, 3...) and one that depends on the row (the same number repeated). Interviewers often ask both back to back to see whether you understand what each loop variable represents.
Example for n = 4:
1
2 2
3 3 3
4 4 4 4
vector<string> repeatedNumberTriangle(int n); // row i: i repeated i times, space-separated
Input n | Output rows | Explanation |
|---|---|---|
| 1 | "1" | One row |
| 3 | "1", "2 2", "3 3 3" | Row i repeats i, i times |
| 5 | "1", "2 2", "3 3 3", "4 4 4 4", "5 5 5 5 5" |
(Confirm: numbers are space-separated with no trailing space; some judges print them without spaces.)
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