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





Hallow 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 
1 2
1 2 3
Example 2:

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

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

oops

Login to see Discussion




Approach


Step-i)initialize i to 1
Step-ii)initialize j to 1
Step-iii)if i is not equal to N print two spaces (" ")
Step-iv)else print j value and space (" ")
Step-v)increment j value by one
Step-vi) repeat steps iii to v till j is less than or equal to i
Step-vii) increment i value by one and go to new line
Step-viii)repeat steps ii to vii till i is less than or equal to N

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


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