Ninja has been given two integers 'M' and βNβ.
Now Ninja has to draw a rectangle of height βMβ and breadth βNβ using the character * such that the * only occurs at the boundaries of the rectangle, and inside of this boundary, there is space only.
Now, Ninja doesnβt know how to perform this operation.
You being Ninja's best friend, your task is to help Ninja to solve this problem.
EXAMPLE:Input: 'M' = 2, βNβ = 2
Output:
**
**
The first line will contain the integer 'T', denoting the number of test cases.
For each test case, one line contains two space-separated integers βMβ and βNβ, where βMβ is the height of the rectangle and βNβ is the breadth of the rectangle.
Output format :
For each test case, print the pattern of height βMβ and breadth βNβ
1 <= 'T' <= 10
1 <= 'M' <= 10^5
1 <= 'N' <= 10^5
1 <= 'M' * 'N' <= 10^5
Time Limit: 1 sec
2
2 2
4 3
**
**
***
* *
* *
***
2
1 1
3 3
*
***
* *
***
What will be the requirement for a pair('I', βJβ) to be present on the boundary?
Approach:
For each (βIβ, βJβ) such that 1 <= βIβ <= βMβ and 1 <= βJβ <= βNβ we have to print either β*β or β β(space). So we have to iterate through all (βIβ, βJβ) pairs and check that if βIβ or βJβ anyone present at the boundary that print β*β else print β β. That is if (βIβ == 1 || βIβ == βMβ || βJβ == 1 || βJβ == βNβ) means that this pair of
('I', βJβ) will come at the boundary.
Algorithm :
O(M * N), Where βMβ is the height of the rectangle and βMβ is the breadth of the rectangle.
As we are iterating over each pair(βIβ, βJβ) such that 1 <= βIβ <= β Mβ and 1 <= βJβ<= β Nβ that means the time complexity will be O(M * N).
O(1).
We are not using an extra space just using the output buffer. So space complexity will be O(1).