Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com

Magical Pattern

Easy
0/40
Average time to solve is 20m
profile
Contributed by
18 upvotes
Asked in companies
Goldman SachsAccentureReliance Jio Infocomm Ltd

Problem statement

You have been given an integer 'N'. Your task is to print the Magical Pattern(see examples) for the given 'N'.

Example :

For 'N' : 4
Pattern :
4 3 2 1 2 3 4                                                                   
3 3 2 1 2 3 3                                                                   
2 2 2 1 2 2 2                                                                   
1 1 1 1 1 1 1                                                                   
2 2 2 1 2 2 2                                                                   
3 3 2 1 2 3 3                                                                   
4 3 2 1 2 3 4
Detailed explanation ( Input/output format, Notes, Images )
Constraints :
1 <= T <= 10
1 <= N <= 10^2

Time Limit : 1 sec
Sample Input 1 :
1
3
Sample Output 1 :
3 2 1 2 3 
2 2 1 2 2  
1 1 1 1 1 
2 2 1 2 2 
3 2 1 2 3 
Sample Input 2 :
1
5
Sample Output 2 :
5 4 3 2 1 2 3 4 5 
4 4 3 2 1 2 3 4 4 
3 3 3 2 1 2 3 3 3 
2 2 2 2 1 2 2 2 2 
1 1 1 1 1 1 1 1 1 
2 2 2 2 1 2 2 2 2 
3 3 3 2 1 2 3 3 3 
4 4 3 2 1 2 3 4 4 
5 4 3 2 1 2 3 4 5 
Full screen
Console