Array ( [0] => [1] => questions [2] => Patterns [3] => Left-Arrow-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
This pattern can be drawn by dividing it to two parts
Step-i)assign 1 to i
Step-ii)assign 1 to j
Step-iii) if i is less than N and i equal to j or i equal to N print * and space(" ")
Step-iv)else print two spaces (" ")
Step-v)increment j value by one
Step-vi)repeat steps iii to v till j is less than or equal to N
Step-vii)go to next line and increment i value by one
Step-viii) repeat steps ii to vii till i is less than or equal to N(Now we are done with upper part)
Step-ix)assign N-1 to i
Step-x)assign 1 to j
Step-xi) if i equals to j print * and space(" ")
Step-xii)else print two spaces (" ")
Step-xiii)increment j value by one
Step-xiv)repeat steps xi to xiii till j is less than or equal to N-1
Step-xv)go to next line and decrement i value by one
Step-xvi) repeat steps x to xv 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