Concentric Number Square

Given a positive integer n, return a square of side length 2n - 1 whose values form concentric layers. The outer layer contains n, each inner layer decreases…

Given a positive integer n, return a square of side length 2n - 1 whose values form concentric layers. The outer layer contains n, each inner layer decreases by one, and the center contains 1. Separate adjacent values with one space. Do not add trailing spaces or a trailing newline.

- 1 ≤ n ≤ 9 - n is always a positive integer.

Example 1: input n = 3; output 3 3 3 3 3 3 2 2 2 3 3 2 1 2 3 3 2 2 2 3 3 3 3 3 3. Distance zero from a border gives 3, distance one gives 2, and the center gives 1.

Example 2: input n = 1; output 1. One layer produces a one-cell square.

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