Problem
Draw a hollow square of side size: the first and last rows are all *, and the rows in between have * only at the two ends with spaces inside.
Implement hollow_square(size).
Input
size: The side length.
Output
Return the rows from top to bottom.
Constraints
1 ≤ size ≤ 50
Examples
Input:
size = 4
Expected output:
expected = ["****", "* *", "* *", "****"]
Input:
long long size = 4;
Expected output:
std::vector<std::string> expected = {"****", "* *", "* *", "****"};
Input:
long size = 4;
Expected output:
string[] expected = new string[] {"****", "* *", "* *", "****"};
Explanation
Rows are "****", "* *", "* *", "****".
Input:
size = 1
Expected output:
expected = ["*"]
Input:
long long size = 1;
Expected output:
std::vector<std::string> expected = {"*"};
Input:
long size = 1;
Expected output:
string[] expected = new string[] {"*"};
Explanation
A 1×1 square is a single "*".
How to approach it
Try on your own first, then open one hint at a time.
Hint 1
The border is filled, while the inside stays empty.
Hint 2
Treat the first and last rows differently from the middle rows.
Hint 3
For size one, the single cell is both border and corner, so it must be filled.
Expected complexity
O(size^2) time, O(size^2) extra space
References
This challenge is adapted for CodeUtility. Follow the statement and constraints above.