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





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

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

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

oops

Login to see Discussion




Approach


Step-i) assign 1 to k
Step-ii) assign N to i
Step-iii) assign k to j
Step-iv) if j is not equal to k and j is not equal to N print two spaces (" ")
Step-v)else print value of j and space (" ")
Step-vi)increment j value by one
Step-vii)repeat steps iv to vi till j is less than or equal to N
Step-viii)go to next line increment k value by one and decrement i value by one
Step-ix)repeat steps iii to viii 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