Centered Star Pyramid
Updated
Problem statement
Given an integer n, return the rows of a centered star pyramid with n rows, from top to bottom.
Rows are numbered from 1. Row i has n - i spaces followed by 2 * i - 1 stars (*). No row has spaces after its last star.
Function
buildPyramid(n: int) → String[]Examples
Example 1
n = 3return = [" *", " ***", "*****"]Row 1 has 2 spaces and 1 star, row 2 has 1 space and 3 stars, and row 3 has no spaces and 5 stars.
Example 2
n = 1return = ["*"]There is one row with one star and no spaces.
Example 3
n = 4return = [" *", " ***", " *****", "*******"]Each row has one fewer space and two more stars than the row above it. Row 4 has no spaces and 7 stars.
Constraints
1 <= n <= 100
More Bank of America Onsite Interview questions
- Employees Without a ManagerONSITE INTERVIEW · Seen Nov 2025
- Longest Substring Without Repeating CharactersONSITE INTERVIEW · Seen Nov 2025
- N-th Fibonacci NumberONSITE INTERVIEW · Seen Nov 2025
- Reverse Each Word in a SentenceONSITE INTERVIEW · Seen Nov 2025
- Second Highest SalaryONSITE INTERVIEW · Seen Nov 2025
- Three Numbers That Add Up to a TargetONSITE INTERVIEW · Seen Apr 2025
- Duplicate RowsONSITE INTERVIEW · Seen Oct 2023
- Factorial of a NumberONSITE INTERVIEW · Seen Oct 2023
- Palindrome String CheckONSITE INTERVIEW · Seen Sep 2023
- Second Largest Element in an ArrayONSITE INTERVIEW · Seen Jun 2023
Similar questions at other companies
- Christmas Tree with N TiersVerily · ONSITE INTERVIEW
- Bounded Word Guess SolverAtlassian · ONSITE INTERVIEWAtlassian interview questions
- Document Edit EventsClickUp · ONSITE INTERVIEW
- Predict Runtime Method DispatchAMD · ONSITE INTERVIEWAMD interview questions
- Basic String Compression with Length GuardNew Relic · PHONE SCREEN · ONSITE INTERVIEW
- Print Sentences as TableAirbnb · PHONE SCREEN · ONSITE INTERVIEWAirbnb interview questions
- Retry with an Attempt LimitOracle · ONSITE INTERVIEWOracle interview questions
- Extract Error Log ContextFlexTrade · ONSITE INTERVIEWFlexTrade interview questions
- Run-Length Encode Consecutive Letter RunsMorgan Stanley · ONSITE INTERVIEWMorgan Stanley interview questions
- String Pattern ReplacementGoogle · PHONE SCREEN · ONSITE INTERVIEWGoogle interview questions