⏱ 00:00
Attempts:0
Best: 0/100
Edge Distance & Nested RingsTarget Time: 20 mins
Concentric Square Pattern
Given an integer N, print a concentric square matrix of size (2*N - 1) x (2*N - 1) where the outermost border is filled with N, the next inner ring is N-1, down to 1 at the center.
Input Format
A single integer N.
Output Format
Print 2*N - 1 rows separated by space.
Constraints:1 <= N <= 9
Concepts Required:
Distance from 4 borders: min(i, j, size-1-i, size-1-j)Ring indexing: N - min_distance
Expected Pattern PreviewASCII Monospace
4 4 4 4 4 4 4 4 3 3 3 3 3 4 4 3 2 2 2 3 4 4 3 2 1 2 3 4 4 3 2 2 2 3 4 4 3 3 3 3 3 4 4 4 4 4 4 4 4
Notice how character spacing and row counts scale systematically based on the input N.
Concrete Examples
Example 1
Input:
4
Output:
4 4 4 4 4 4 4 4 3 3 3 3 3 4 4 3 2 2 2 3 4 4 3 2 1 2 3 4 4 3 2 2 2 3 4 4 3 3 3 3 3 4 4 4 4 4 4 4 4
Explanation: The matrix has size 7x7 with concentric rings decreasing from 4 down to 1.
