PPractick

DSA interview question

Pattern 12: Number Crown

Easy · Algorithms · Topics: pattern building

The problem

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

Function signature

vector<string> numberCrown(int n);  // row i: 1..i, 2(n - i) spaces, i..1

Test cases

Input nOutput rowsExplanation
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
4as in the exampleEvery row is 2n characters wide

(Confirm: 1 ≤ n ≤ 9 so all numbers are single digits; no separators between digits.)

How interviewers phrase it

Clarifying questions to ask

  1. Is N at most 9? (Multi-digit numbers break alignment.)
  2. Should digits be separated by spaces?
  3. Print or return?

Follow-ups to expect

  1. "How did you get 2(n − i) spaces?"
  2. "Why does the last row have no gap?"
  3. "What's the complexity?"

Practise questions like this with a real engineer

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 interview

Related questions

All 474 dsa interview questions

DSA mock interviews · System design interview questions · Free mock interview practice · Browse interviewers · Sign in