PPractick

DSA interview question

Pattern 4: Triangle of Repeated Row Numbers

Easy · Algorithms · Topics: pattern building

The problem

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

Function signature

vector<string> repeatedNumberTriangle(int n);  // row i: i repeated i times, space-separated

Test cases

Input nOutput rowsExplanation
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.)

How interviewers phrase it

Clarifying questions to ask

  1. Space-separated or not?
  2. Trailing spaces allowed?
  3. Print or return?

Follow-ups to expect

  1. "What's the one change from Pattern 3?"
  2. "How would you print the sum of each row?"
  3. "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