![]() |
VOOZH | about |
Given an integer N, the task is to print half-diamond-star pattern.
*
**
***
****
*****
******
*****
****
***
**
*
Examples:
Input: N = 3 Output: * ** *** ** * Input: N = 6 Output: * ** *** **** ***** ****** ***** **** *** ** *
Approach: The idea is to break the pattern into two halves that is upper half and lower half. Then print them separately with the help of the loops. The key observation for printing the upper half and lower half is described as below:
Number of '*' in ith line =
Number of '*' in ith line =
* ** *** **** ***** **** *** ** *
Time complexity: O(N2) where N is given integer
Auxiliary Space: O(1)