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





Vertical Equilibrium 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 2
3 3 3
Example 2:

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

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

oops

Login to see Discussion




Approach


Step-i)initialize i to 1
Step-ii) initialize space to 1
Step-iii) print spaces (" ")
Step-iv)increment space by one value
Step-v)repeat steps iii to iv till space is less than or equal to N-i
Step-vi) assign 1 to j
Step-vii) print the value of i and space and then increase the value of j by one
Step-viii)repeat the step vii till j is less than or equal to i
Step-ix) go to next line and increment the value of i
Step-x) repeat the steps ii to ix till i is less than or equal to N

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