आसान 0 हल किए गए 0% स्वीकृति

Pyramid Rows

Draw a right-aligned pyramid of # blocks.

आप क्या सीखेंगे

  • पैडिंग और ब्लॉक से पंक्तियाँ बनाना
  • हर पंक्ति के स्पेस और चिह्न गिनना
  • पंक्तियों को सूची के रूप में लौटाना

समस्या

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

उदाहरण

उदाहरण 1
इनपुट:
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.

उदाहरण 2
इनपुट:
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 के लिए अनुकूलित की गई है। ऊपर दिए गए स्टेटमेंट और सीमाओं का पालन करें।

दूसरों से सीखें

समुदाय समाधान

अभी तक कोई प्रकाशित समाधान नहीं। पहला साझा करने के लिए इस चुनौती को हल करें।