Build a star pyramid pattern
Coding problemEasyAsked in: Accenture, Capgemini, Cognizant
Given a number of rows n, build a centred pyramid of stars and return its rows from top to bottom, one text line per row.
Row i (counting from 1) has n - i spaces followed by 2i - 1 stars (the * character), and nothing after the stars. For n = 0 return an empty list.
Examples
Example 1
Input: n = 3
Output: [" *"," ***","*****"]
Example 2
Input: n = 1
Output: ["*"]
Example 3
Input: n = 0
Output: []
Constraints
- n is between 0 and 200
Run checks the 3 examples. Submit also runs the hidden tests: edge cases, large inputs and a time limit.
Run your code to see the results here. Ctrl or Cmd + Enter runs; add Shift to submit.