529.Print a Hollow Inverted Right Triangle Star Pattern
Easy
Given
n, return the n rows of an upside-down hollow right triangle: the first row is n stars, and each row after it is one cell narrower, keeping stars only at its two ends.
This is the Hollow Right Triangle flipped vertically, so the solid edge moves from the bottom to the top. The same edge testEdge TestChecking whether a cell lies on the outline: first cell, last cell, or the solid side of the shape. applies, but the width now shrinks (n − i + 1) instead of growing, and the special one-cell tip arrives at the end rather than the start.
Example 1:
Input: n = 5
Output: ["*****","* *","* *","**","*"]
Example 2:
Input: n = 2
Output: ["**","*"]
+ 4 hidden test cases run on Submit.
Constraints:
- ●
1 ≤ n ≤ 20
n =
5