Pattern 22

Think before you code.

Print concentric square layers of numbers that count down from n at the edges to 1 in the center.

easy

Pattern 22

Given an integer n. You need to recreate the pattern given below for any value of N. Let's say for N = 5, the pattern should look like as below:

5 5 5 5 5 5 5 5 5
5 4 4 4 4 4 4 4 5
5 4 3 3 3 3 3 4 5
5 4 3 2 2 2 3 4 5
5 4 3 2 1 2 3 4 5
5 4 3 2 2 2 3 4 5
5 4 3 3 3 3 3 4 5
5 4 4 4 4 4 4 4 5
5 5 5 5 5 5 5 5 5

Print the pattern in the function given to you.

Example 1

  • Input : n = 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

Example 2

  • Input : n = 2
  • Output :
2 2 2
2 1 2
2 2 2

Constraints

1 <= n <= 100

Fun facts

  • One real-world application of this problem is in graphic design software and games, where such patterns might be used to create programmatically generated visuals or puzzles.
  • Understanding how to construct complex patterns from simple mathematical rules is a fundamental aspect of procedural generation, a technique commonly used in game design to create vast, explorable worlds on the fly.