PPractick

DSA interview question

Pattern 8: Inverted Star Pyramid

Easy · Algorithms · Topics: pattern building

The problem

Now turn the pyramid upside down: the first row is the widest (2n − 1 stars) and each row below loses a star on each side while gaining a leading space, until the last row has a single centred star. It tests whether you can derive formulas for a decreasing symmetric row, i − 1 spaces and 2(n − i) + 1 stars, instead of relying on the pyramid's formulas by memory.

Example for n = 3:

*****
 ***
  *

Function signature

vector<string> invertedPyramid(int n);  // row i: i - 1 spaces, then 2(n - i) + 1 stars

Test cases

Input nOutput rowsExplanation
1"*"One star
2"***", " *"Widest row first
3"*****", " ***", " *"Spaces grow by one, stars shrink by two
4"*******", " *****", " ***", " *"

(Confirm: no trailing spaces; exactly n rows.)

How interviewers phrase it

Clarifying questions to ask

  1. Is N the number of rows?
  2. Trailing spaces or not?
  3. Print or return?

Follow-ups to expect

  1. "How did you get 2(n − i) + 1?"
  2. "Is there a simpler way?"
  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