Array ( [0] => [1] => questions [2] => Patterns [3] => Standing-Star-Triangle ) Patterns | Standing Star Triangle | THE INQUISITIVE





Standing Star 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
*
* *
* * *
* * *
* *
*
Example 2:

Input
4
Output
*
* *
* * *
* * * *
* * * *
* * *
* *
*
Example 3:

Input
5
Output
*
* *
* * *
* * * *
* * * * *
* * * * *
* * * *
* * *
* *
*

oops

Login to see Discussion




Approach

Note:- this problem can be solved by dividing it to two parts
first part prints the upper part of the problem
second part prints the lower part of the problem

Step-i)assign 1 to i
Step-ii) assign 1 to j
Step-iii) print * and space (" ")
Step-iv) increment j value by one
Step-v) repeat steps iii and iv till j is less than or equal to i
Step-vi) go to next line and increment i value by one
Step-vii) repeat steps ii to vi till i is less than or equal to N
( By now we are done with the upper part of the pattern)
Step-viii)assign N to i
Step-ix) assign to 1 to j
Step-x)print * and space (" ")
Step-xi)increment j by one value
Step-xii)repeat steps x and xi till j is less or equal to i
Step-xiii) go to new line and increment i value by one
Step-xiv)repeat steps ix to xiii till i is greater than or equal to i

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