DSA interview question
The symmetric void is a rectangle of stars with a diamond-shaped hole in the middle. The top half starts with a full row of stars, and a gap opens in the centre that widens by two each row. The bottom half closes it again. Each row has three segments (stars, gap, stars), and the challenge is writing the formulas for all three in both halves without off-by-one errors.
Example for n = 5:
**********
**** ****
*** ***
** **
* *
* *
** **
*** ***
**** ****
**********
vector<string> symmetricVoid(int n); // 2n rows, each 2n characters wide
Input n | Output rows | Explanation |
|---|---|---|
| 1 | "**", "**" | Each half is one full row with no gap |
| 2 | "****", "* *", "* *", "****" | Gap of 2 in the middle rows |
| 3 | "******", "** **", "* *", "* *", "** **", "******" | Gap widens 0, 2, 4, then closes |
| 5 | as in the example | Every row is 2n = 10 characters |
(Confirm: 2n rows, with the widest gap appearing twice. Every row is exactly 2n characters and ends 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