समस्या
Draw a right-aligned pyramid like the one in Super Mario: row i (counting from 1) has height − i spaces followed by i # characters.
Implement pyramid_rows(height).
Input
height: The number of rows.
Output
Return the rows from top to bottom.
सीमाएँ
0 ≤ height ≤ 50
उदाहरण
इनपुट:
height = 3
अपेक्षित आउटपुट:
expected = [" #", " ##", "###"]
इनपुट:
long long height = 3;
अपेक्षित आउटपुट:
std::vector<std::string> expected = {" #", " ##", "###"};
इनपुट:
long height = 3;
अपेक्षित आउटपुट:
string[] expected = new string[] {" #", " ##", "###"};
व्याख्या
Rows are " #", " ##" and "###": each row has one more block and one less space.
इनपुट:
height = 1
अपेक्षित आउटपुट:
expected = ["#"]
इनपुट:
long long height = 1;
अपेक्षित आउटपुट:
std::vector<std::string> expected = {"#"};
इनपुट:
long height = 1;
अपेक्षित आउटपुट:
string[] expected = new string[] {"#"};
व्याख्या
A single row with one block: "#".
कैसे हल करें
पहले खुद कोशिश करें, फिर एक-एक करके संकेत खोलें।
संकेत 1
Har row mein leading spaces aur badhta hua hash characters ka run hota hai.
संकेत 2
Rows ko top se bottom tak ek-ek karke banao, taaki alignment sahi rahe.
संकेत 3
Agar height zero ho, to koi rows return mat karo; empty-looking pyramid nahi.
अपेक्षित जटिलता
समय O(height^2), अतिरिक्त स्थान O(height^2)
संदर्भ
यह चुनौती CodeUtility के लिए अनुकूलित की गई है। ऊपर दिए गए स्टेटमेंट और सीमाओं का पालन करें।