Number Palindrome Pyramid

Given a positive integer n, return a centered number-palindrome pyramid with n rows. Row i begins with n - i spaces, climbs from 1 to i, and then descends…

Given a positive integer n, return a centered number-palindrome pyramid with n rows. Row i begins with n - i spaces, climbs from 1 to i, and then descends from i - 1 back to 1. Do not place spaces between digits or at the end of a row. Join adjacent rows with one newline character and do not add a trailing newline.

- 1 ≤ n ≤ 9 - n is always a positive integer. - Each row contains only single decimal digits, so n is at most 9.

Example 1: input n = 4; output 1 121 12321 1234321. Each row is centered, reaches its row number once, and mirrors back to 1.

Example 2: input n = 1; output 1. The smallest pyramid contains the single digit 1.

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