Array ( [0] => [1] => questions [2] => Basic [3] => Reverse-Right-angle-Triangle ) Patterns | Reverse Right angle Triangle | THE INQUISITIVE





Reverse Right angle Triangle

LEVEL:Beginner

Description

Print the pattern as shown below for all test cases.

Input Format

First line contains the value N.

Output Format

Print the output as shown in below examples.


Example 1:

Input
3
Output
1 2 3
1 2
1
Example 2:

Input
5
Output
1 2 3 4 5
1 2 3 4
1 2 3
1 2 
1
Example 3:

Input
6
Output
1 2 3 4 5 6
1 2 3 4 5
1 2 3 4
1 2 3 
1 2 
1 

oops

Login to see Discussion




Approach


Step-i) assign N to i
Step-ii) assign 1 to j
Step-iii)print value of j and space (" ")
Step-iv) increment j value by one
Step-v) repeat steps iii to iv till j is less than or equal to i
Step-vi) go to new line and decrement i value by one
Step-vii) repeat steps ii to vi till i is greater than or equal to 1

Time Complexity: O(n^2)
Space Complexity: O(1)


Note :

Let us know if you can come up with a better approach, mail us at support@theinquisitive.in Your approach will be reviewed and posted with credits to you.

oops

Login to see Solution