DSA interview question
The number crown has numbers climbing up from the left edge and back down on the right, with a gap in the middle that closes row by row. Each row has three segments: count up 1..i, a gap of 2(n − i) spaces, then count down i..1. The last row has no gap at all, so the two halves meet. It's good practice for patterns whose middle segment shrinks while the outer segments grow.
Example for n = 4:
1 1
12 21
123 321
12344321
vector<string> numberCrown(int n); // row i: 1..i, 2(n - i) spaces, i..1
Input n | Output rows | Explanation |
|---|---|---|
| 1 | "11" | No gap in the only row |
| 2 | "1 1", "1221" | Gap of 2, then none |
| 3 | "1 1", "12 21", "123321" | Gap shrinks by 2 each row |
| 4 | as in the example | Every row is 2n characters wide |
(Confirm: 1 ≤ n ≤ 9 so all numbers are single digits; no separators between digits.)
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