DSA interview question
You're starting a series of pattern exercises, and the first one is the simplest possible shape: an n × n square of stars. It's the base every other pattern builds on. The outer loop controls the rows, the inner loop controls what goes in each row, and here every row is identical. Getting this one right (with the right number of rows and columns, and nothing extra at the ends) sets up the mental model for the next twenty patterns.
Example for n = 3:
***
***
***
vector<string> squarePattern(int n); // n rows, each with n stars
Input n | Output rows | Explanation |
|---|---|---|
| 1 | "*" | One row, one star |
| 3 | "***", "***", "***" | Three identical rows |
| 5 | five rows of "*****" | Rows and columns both equal n |
(Confirm: stars are printed without separators; some judges, such as GeeksforGeeks, expect a space after each star, which only changes what is appended in the inner loop.)
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