PPractick

DSA interview question

Pattern 17: Alpha Hill

Easy · Algorithms · Topics: pattern building

The problem

The alpha hill is a centred pyramid of letters where each row climbs from A up to the row's peak letter and back down: A, ABA, ABCBA. It reuses the star pyramid's spacing (n − i leading spaces, 2i − 1 characters) but fills the characters with a palindrome instead of stars. It's a nice test of whether you can combine a known shape with a new content rule, and of handling the "peak" character exactly once.

Example for n = 4:

   A
  ABA
 ABCBA
ABCDCBA

Function signature

vector<string> alphaHill(int n);  // row i: n - i spaces, then A..(i-th letter)..A

Test cases

Input nOutput rowsExplanation
1"A"
2" A", "ABA"
3" A", " ABA", "ABCBA"Peak letter appears once per row
4as in the exampleRow i has 2i − 1 letters

(Confirm: 1 ≤ n ≤ 26; leading spaces for centring, no trailing spaces.)

How interviewers phrase it

Clarifying questions to ask

  1. N at most 26?
  2. Trailing spaces allowed?
  3. Print or return?

Follow-ups to expect

  1. "How is this related to the star pyramid?"
  2. "How do you make sure the peak letter isn't repeated?"
  3. "Can you compute each character from its position?"
  4. "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