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

Alphabet Triangle

Print a right triangle of letters where row i spells the first i letters of the alphabet.

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

  • Turn a number into a letter by offsetting from 'A'
  • Build rows of growing length
  • Return a pattern as a list of rows

समस्या

अनुवाद दिखाएँ

Instead of stars, this right triangle uses the alphabet. Row i (counting from 1) holds the first i uppercase English letters in order, written next to each other with no spaces: row 1 is A, row 2 is AB, row 3 is ABC. Turning a position into a letter is a matter of adding it to the character code of A.

Implement alphabet_triangle(n).

Input

n: The number of rows (at most 26, one per letter).

Output

Return the rows from top to bottom.

सीमाएँ

0 ≤ n ≤ 26

उदाहरण

उदाहरण 1
इनपुट:
n = 4

अपेक्षित आउटपुट:
expected = ["A", "AB", "ABC", "ABCD"]
इनपुट:
long long n = 4;

अपेक्षित आउटपुट:
std::vector<std::string> expected = {"A", "AB", "ABC", "ABCD"};
इनपुट:
long n = 4;

अपेक्षित आउटपुट:
string[] expected = new string[] {"A", "AB", "ABC", "ABCD"};

व्याख्या

Each row adds the next letter: ["A", "AB", "ABC", "ABCD"].

उदाहरण 2
इनपुट:
n = 1

अपेक्षित आउटपुट:
expected = ["A"]
इनपुट:
long long n = 1;

अपेक्षित आउटपुट:
std::vector<std::string> expected = {"A"};
इनपुट:
long n = 1;

अपेक्षित आउटपुट:
string[] expected = new string[] {"A"};

व्याख्या

Only A: ["A"].

कैसे हल करें

पहले खुद कोशिश करें, फिर एक-एक करके संकेत खोलें।

संकेत 1

Position j in a row (from 0) is the letter j places after A.

संकेत 2

Most languages let you add an integer to a character code and turn it back into a character.

संकेत 3

Row i is just row i − 1 with one more letter.

अपेक्षित जटिलता

O(n^2) time, O(n^2) extra space

संदर्भ

यह चुनौती CodeUtility के लिए अनुकूलित की गई है। ऊपर दिए गए स्टेटमेंट और सीमाओं का पालन करें।

हर कोडर का सबसे अच्छा पास हुआ समाधान। तेज़, कम मेमोरी वाले और बेहतर रेटिंग वाले समाधान ऊपर रहते हैं।

अभी कोई पास हुआ समाधान नहीं है। इसे हल करें और पहला स्थान पाएँ।

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

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

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