समस्या
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.
सीमाएँ
1 ≤ size ≤ 50
उदाहरण
इनपुट:
size = 4
अपेक्षित आउटपुट:
expected = ["****", "* *", "* *", "****"]
इनपुट:
long long size = 4;
अपेक्षित आउटपुट:
std::vector<std::string> expected = {"****", "* *", "* *", "****"};
इनपुट:
long size = 4;
अपेक्षित आउटपुट:
string[] expected = new string[] {"****", "* *", "* *", "****"};
व्याख्या
Rows are "****", "* *", "* *", "****".
इनपुट:
size = 1
अपेक्षित आउटपुट:
expected = ["*"]
इनपुट:
long long size = 1;
अपेक्षित आउटपुट:
std::vector<std::string> expected = {"*"};
इनपुट:
long size = 1;
अपेक्षित आउटपुट:
string[] expected = new string[] {"*"};
व्याख्या
A 1×1 square is a single "*".
कैसे हल करें
पहले खुद कोशिश करें, फिर एक-एक करके संकेत खोलें।
संकेत 1
Border filled hota hai, aur andar ka hissa empty rehta hai.
संकेत 2
Middle rows se alag first aur last rows ko handle karo.
संकेत 3
Size one ke case mein single cell hi border aur corner dono hai, isliye woh filled hona chahiye.
अपेक्षित जटिलता
समय O(size^2), अतिरिक्त स्थान O(size^2)
संदर्भ
यह चुनौती CodeUtility के लिए अनुकूलित की गई है। ऊपर दिए गए स्टेटमेंट और सीमाओं का पालन करें।