You are given an integer N. Your task is to print a diamond pattern of stars consisting of 2N − 1 rows. The pattern must contain an upward centered pyramid of N rows, followed by an inverted centered pyramid of N − 1 rows. The number of stars increases by two in each row until the middle row, then decreases by two symmetrically.
Input: N = 4
Output:
*
Explanation: The diamond contains 7 rows. The number of stars increases from 1 to 7, then decreases symmetrically to 1, with appropriate leading spaces to keep the pattern centered.
Input: N = 1
Output:
*
Explanation: A single row containing one star forms the smallest possible diamond.
Input: N = 2
Output:
*
Explanation: The diamond contains three rows, with 1 star in the first and last rows and 3 stars in the middle row.
Sign in to write, run, and submit your solution against the full test suite.