You are given an integer βNβ, βNβ will always be an odd integer. Your task is to print a pattern with the following description:
1. The pattern will consist of βNβ lines.
2. The pattern will consist of β β (space) and β*β characters only.
3. The pattern will be a βVoid of Diamondβ pattern.
4. A βVoid of Diamondβ pattern is a pattern βNβ * βNβ cells and β β characters make a diamond shape and β*β fill all other points.
5. For a better understanding of the βVoid of Diamondβ pattern refer to example and sample input-output.
For example:
If βNβ is 5 then the pattern will be-
*****
** **
* *
** **
*****
Input Format:
The first line of input contains an integer 'T' representing the number of test cases.
Then each test case contains a single integer βNβ denoting the size of the pattern.
Output Format:
For each test case, print 'N' strings denoting the pattern.
The output of each test case will be printed in a separate line.
Constraints:
1 <= T <= 5
3 <= N <= 500
Where βTβ is the number of test cases, βNβ is the size of the pattern. βNβ will be odd for all test cases.
Note:
You do not need to print anything, it has already been taken care of. Just implement the given function.
2
5
3
*****
** **
* *
** **
*****
***
* *
***
Test Case 1:
Given βNβ = 5
We will print the pattern as the description of the βVoid of Diamondβ pattern.
Test Case 2:
Given βNβ = 3
There will be only 1 β β space in the diamond pattern.
2
7
9
*******
*** ***
** **
* *
** **
*** ***
*******
*********
**** ****
*** ***
** **
* *
** **
*** ***
**** ****
*********
Test Case 1:
Given βN' = 7
The pattern is printed such that β β making a diamond and β*β filling other points.
Test Case 2:
Given βNβ = 9
Created a 9*9 grid and all space cells make a diamond pattern.
We can see the βNβ * βNβ grid as an x-y plane, and can easily divide it into 4 symmetric parts and is there any relation of β β characters with coordinates?
The idea is here to visualize the problem in a different way, here βNβ will be odd so along the middle vertical line and middle horizontal this βNβ * βNβ grid can be divided into 4 symmetric parts and we can see it as an x-y plane. So we can see this βNβ * βNβ grid as a square on coordinate axis with the bottom left corner at { -((βNβ - 1) / 2), -((βNβ - 1) / 2)} and upper right corner at { (βNβ - 1) / 2 , (βNβ - 1) / 2}.
Now if we assign coordinates to all other points as {x, y} we will find that in a quadrant all β β cells will form a triangular region and if we combined them all we will get a mathematical equation as |x| + |y| < (βNβ - 1) / 2.
So now we run 2 loops for all coordinates and make a character β β if the sum of the absolute value of coordinates is less than ( βNβ - 1) / 2 otherwise it will be a β*β character and here we can say in this case we will generate the pattern in a way such that first, we will generate the bottom line then will move till the top line but actually it wonβt affect our pattern because it is symmetric with the horizontal bisector.
O(N ^ 2), where N is the size of the pattern.
We are traversing each point of the βNβ * βNβ grid so we are doing βNβ ^ 2 iterations here so the overall time complexity is O(N ^ 2).
O(N ^ 2), where N is the size of the pattern.
As we will be storing the result in an array of strings that contains βNβ strings of size βNβ so overall space complexity will be O(N ^ 2).