Problema
Build one row of a multiplication table: number × 1, number × 2, … up to number × count.
Implement multiplication_row(number, count).
Input
number: The number to multiply. count: How many multiples to list.
Output
Return the list of multiples in order.
Vincoli
-1,000 ≤ number ≤ 1,000; 0 ≤ count ≤ 100
Esempi
Input:
count = 5
number = 3
Output atteso:
expected = [3, 6, 9, 12, 15]
Input:
long long count = 5;
long long number = 3;
Output atteso:
std::vector<long long> expected = {3, 6, 9, 12, 15};
Input:
long count = 5;
long number = 3;
Output atteso:
long[] expected = new long[] {3, 6, 9, 12, 15};
Spiegazione
3×1, 3×2, 3×3, 3×4, 3×5 = 3, 6, 9, 12, 15.
Input:
count = 0
number = 7
Output atteso:
expected = []
Input:
long long count = 0;
long long number = 7;
Output atteso:
std::vector<long long> expected = {};
Input:
long count = 0;
long number = 7;
Output atteso:
long[] expected = new long[] {};
Spiegazione
Zero multiples were requested, so the list is empty.
Come affrontarlo
Prova prima da solo, poi apri un suggerimento alla volta.
Suggerimento 1
Each entry is the same number multiplied by a growing counter.
Suggerimento 2
Build the results in order from 1 through the requested count.
Suggerimento 3
If the count is zero, the result should be an empty list.
Complessità attesa
O(count) time, O(count) extra space
Riferimenti
Questa sfida è adattata per CodeUtility. Segui la traccia e i vincoli sopra.