DSA interview question
This pattern combines the shrinking shape of Pattern 5 with the counting rows of Pattern 3: the first row prints 1 2 ... n, and each following row stops one number earlier, until the last row prints just 1. It checks whether you can combine two ideas you've already used: the row length comes from the row number (n − i + 1), while the printed value comes from the column (j).
Example for n = 4:
1 2 3 4
1 2 3
1 2
1
vector<string> invertedNumberTriangle(int n); // row i: "1 2 ... (n - i + 1)"
Input n | Output rows | Explanation |
|---|---|---|
| 1 | "1" | One row |
| 3 | "1 2 3", "1 2", "1" | Each row counts up from 1 and ends one earlier |
| 5 | "1 2 3 4 5", "1 2 3 4", "1 2 3", "1 2", "1" |
(Confirm: numbers are space-separated with no trailing space; some judges print them without spaces.)
n n−1 ... 1 in each row instead?"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