DSA interview question
The second exercise in the pattern series turns the square into a right-angled triangle: the first row has one star, the second has two, and so on until the last row has n. It introduces the single most important idea in pattern problems: the inner loop's bound depends on the row number. Once you see that the number of stars in row i is just i, the change from Pattern 1 is a single character in the code.
Example for n = 4:
*
**
***
****
vector<string> rightTriangle(int n); // row i (1-indexed) has i stars
Input n | Output rows | Explanation |
|---|---|---|
| 1 | "*" | One row |
| 3 | "*", "**", "***" | Row i has i stars |
| 5 | "*", "**", "***", "****", "*****" | Last row has n stars |
(Confirm: rows are left-aligned with no leading spaces; stars have no 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