समस्या
Build an n × n multiplication table: the value in row i, column j (both counting from 1) is i × j.
Implement multiplication_grid(n).
Input
n: The table size.
Output
Return the table as a list of rows.
सीमाएँ
0 ≤ n ≤ 20
उदाहरण
इनपुट:
n = 3
अपेक्षित आउटपुट:
expected = [
[1, 2, 3],
[2, 4, 6],
[3, 6, 9]
]
इनपुट:
long long n = 3;
अपेक्षित आउटपुट:
std::vector<std::vector<long long>> expected = {
{1, 2, 3},
{2, 4, 6},
{3, 6, 9}
};
इनपुट:
long n = 3;
अपेक्षित आउटपुट:
long[][] expected = new long[][] {
new long[] {1, 2, 3},
new long[] {2, 4, 6},
new long[] {3, 6, 9}
};
व्याख्या
Rows are [1, 2, 3], [2, 4, 6] and [3, 6, 9].
इनपुट:
n = 1
अपेक्षित आउटपुट:
expected = [
[1]
]
इनपुट:
long long n = 1;
अपेक्षित आउटपुट:
std::vector<std::vector<long long>> expected = {
{1}
};
इनपुट:
long n = 1;
अपेक्षित आउटपुट:
long[][] expected = new long[][] {
new long[] {1}
};
व्याख्या
A 1×1 table holds only 1 × 1 = 1.
कैसे हल करें
पहले खुद कोशिश करें, फिर एक-एक करके संकेत खोलें।
संकेत 1
Har cell bas apni row number aur column number ka product hai.
संकेत 2
Table ko row by row banao, aur har row ko left to right fill karo.
संकेत 3
Zero-size case mein empty table return karo, single empty row nahi.
अपेक्षित जटिलता
समय O(n^2), अतिरिक्त स्थान O(n^2)
संदर्भ
यह चुनौती CodeUtility के लिए अनुकूलित की गई है। ऊपर दिए गए स्टेटमेंट और सीमाओं का पालन करें।