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





Horizontal 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*3
4*5*6
4*5*6
2*3
1
Example 2:

Input
4
Output
1
2*3
4*5*6
7*8*9*10
7*8*9*10
4*5*6
2*3
1
Example 3:

Input
5
Output
1
2*3
4*5*6
7*8*9*10
11*12*13*14*15
11*12*13*14*15
7*8*9*10
4*5*6
2*3
1

oops

Login to see Discussion




Approach


Step-i) assign 1 to count and k
Step-ii) assign 1 to i
Step-iii) assign 1 to j
Step-iv)if j not equals to 1 and less than or equal to count print * and k else print only k
Step-v) increment k by one value
Step-vi)repeat steps iv and v till j is less than or equal to count
Step-vii)go to next line increment k and i by one value
Step-viii)repeat steps iii to vii till i is less than or equal to N
Step-ix) assign k-N-1 to k
Step-x) assign 1 to i
Step-xi) assign 1 to j
Step-xii)if j not equals to 1 and less than or equal to count print * and k+j else print only k+j
Step-xiii) increment k by one value
Step-xiv)repeat steps iv and v till j is less than count
Step-xv)decrement count by one value, assign k = k-N+i, go to new line and increment i by one value
Step-xvi)repeat steps xi to xv 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