DSA interview question
The hollow square draws only the border of an n × n square: the first and last rows are solid, and every row in between has a star at each end with spaces inside. It's the first pattern where the character at a position depends on a condition (is this cell on the border?) rather than a simple count, which is exactly how grid problems check boundaries later on.
Example for n = 4:
****
* *
* *
****
vector<string> hollowSquare(int n); // n rows of n characters; stars on the border only
Input n | Output rows | Explanation |
|---|---|---|
| 1 | "*" | A single cell is all border |
| 2 | "**", "**" | Every cell is on the border |
| 3 | "***", "* *", "***" | One interior cell |
| 4 | "****", "* *", "* *", "****" | A 2 × 2 interior |
(Confirm: the pattern is an n × n square; interior rows end with a star, so there are no trailing 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