Rectangular Numbers

Ninja has a number ‘N’. He wants to print the pattern in such a way that the outer rectangle is of the number ‘N’ and the number goes on decreasing as we move inside the rectangles.

For example, if ‘N’ = 4, then pattern will be:

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 
Input Format:
The first line contains an integer 'T' which denotes the number of test cases or queries to be run.

The first line of each test case contains one integer ‘N’ for the number of rectangles.
Output Format:
For each case, return a 2-d list/array of integers denoting the pattern.

The output of each test case will be printed in a separate line.
Note:
You do not need to input or print anything, and it has already been taken care of. Just implement the given function.
Constraints:
1 <= T <= 5
1 <= N <= 100

Time limit: 1 sec.
CodingNinjas
author
2y

The number of rows or columns to be printed for given n will be 2*n – 1.
We will print the matrix in two parts. First, print the upper half from rows from 0 to floor((2*n – 1)/2) and then second half ...read more

CodingNinjas
author
2y
Pattern Observation

As we need to move rectangles for each number from N to 1, we start with a loop where N is decreasing after iteration of the loop. Inside the loop, we basically only need to choose ...read more

Help your peers!
Add answer anonymously...
Athenahealth Technology Software Developer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions
Get AmbitionBox app

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter