Array ( [0] => [1] => questions [2] => Basic [3] => Right-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
Note : this problem can be solved by dividing it to two subproblems
Step-i) initialize i to 1
Step-ii) initialize j to 1
Step-iii) if i is less than N and j is equal to N-i+1 or i equal to N or i is greater than N and j is equal to i-N+1 print star 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 viii till i is less than or equal to 2*N-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