X Star Pattern

Given a positive odd integer n, return an n × n X made of stars. Place a star where the zero-based row and column are equal, or where their sum is n - 1. Use…

Given a positive odd integer n, return an n × n X made of stars. Place a star where the zero-based row and column are equal, or where their sum is n - 1. Use spaces everywhere else. Remove trailing spaces from every row, but preserve leading and interior spaces. Join adjacent rows with one newline character and do not add a trailing newline.

- 1 ≤ n ≤ 9 - n is always odd. - The two diagonals meet in one center cell.

Example 1: input n = 5; output * * * * * * * * *. Stars occupy the main and opposite diagonals, meeting at the center.

Example 2: input n = 1; output *. Both diagonals are the same single cell.

Category: Pattern Programs. Topic: pattern-programs. Difficulty: Easy. Patterns: math.