Array ( [0] => [1] => questions [2] => Patterns [3] => 270-degrees-Triangle-with-stars )
Print the pattern as shown below for all test cases.
First line contains the value N.
Print the output as shown in below examples.
3
* * * * * *
4
* * * * * * * * * *
5
* * * * * * * * * * * * * * *
Login to see Discussion
Step-i)initialize i to N
Step-ii) initialize space to 1
Step-iii) print space 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)initialize j to 1
Step-vii)print * and space (" ")
Step-viii)increment j value by one
Step-ix) repeat steps vii and vii till j is less than or equal to i
Step-x) go to next line and decrement i value by one
Step-xi)repeat steps ii to x 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.
Login to see Solution