Array ( [0] => [1] => questions [2] => Arrays [3] => Hallow-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 1
Step-ii) initialize space to 1
Step-iii) print two 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)if i equal to one go to next step else go to xi
Step-vii) assign 1 to j
Step-viii) print * and space (" ")
Step-ix)increment j by one value
Step-x) repeat steps viii and ix till j is less than or equal to N
Step-xi)assign 1 to j
Step-xii)if j equal to 1 are j equal to 2*i-1 print *
Step-xiii)else print space
Step-xiv)increment j by one value
Step-xv)repeat steps xii to xiv till j is less than 2*i-1
Step-xvi) go to new line and increment i by one value
Step-xvii) repeat steps ii to xvi 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.
Login to see Solution