Dataford
Interview QuestionsInterview GuidesExperiencesMock InterviewsPricing
Get started
Generate a Pyramid Pattern
00:00
5 left

Generate a Pyramid Pattern

EasyPython

Problem

Barco ClickShare QA tooling can use predictable text patterns to verify alignment and rendering in a shared display preview. Write a function that generates a centered pyramid pattern with a configurable height and style.

For each row, use exactly 2 * row - 1 visible positions. A filled pyramid contains the symbol throughout each row. A hollow pyramid contains the symbol only at the left edge, right edge, and across the entire base. Leading spaces must center the pyramid, and trailing spaces must be removed.

Formal Specification

Implement generate_pyramid(height, hollow), where height is a positive integer and hollow is a Boolean. Return a list of strings from the top row to the base row. Use "*" as the symbol. The first row has one symbol, and the final row has 2 * height - 1 symbols.

Constraints

  • 1 <= height <= 1000
  • hollow is a Boolean
  • The output contains exactly height rows
  • Each row has no trailing spaces

Function Signature

def generate_pyramid(height, hollow):
Interviewer

Your question is Generate a Pyramid Pattern. Start with the requirements in the Question tab.

Run and submit as often as you like. When you're ready, talk me through your approach or go straight to the code.

You need to log in / sign up to run or submit.
CodePython 3
You need to log in / sign up to run or submit.Ln 2
Run your code to see test output here.