All challenges
Easy 0 solved 0% acceptance

Multiplication Table Row

List the first multiples of a number.

What you'll learn

  • Generate multiples in a loop
  • Build and return a list
  • Control the number of iterations

Problem

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.

Constraints

-1,000 ≤ number ≤ 1,000; 0 ≤ count ≤ 100

Examples

Example 1
Input:
count = 5
number = 3

Expected output:
expected = [3, 6, 9, 12, 15]
Input:
long long count = 5;
long long number = 3;

Expected output:
std::vector<long long> expected = {3, 6, 9, 12, 15};
Input:
long count = 5;
long number = 3;

Expected output:
long[] expected = new long[] {3, 6, 9, 12, 15};

Explanation

3×1, 3×2, 3×3, 3×4, 3×5 = 3, 6, 9, 12, 15.

Example 2
Input:
count = 0
number = 7

Expected output:
expected = []
Input:
long long count = 0;
long long number = 7;

Expected output:
std::vector<long long> expected = {};
Input:
long count = 0;
long number = 7;

Expected output:
long[] expected = new long[] {};

Explanation

Zero multiples were requested, so the list is empty.

How to approach it

Try on your own first, then open one hint at a time.

Hint 1

Each entry is the same number multiplied by a growing counter.

Hint 2

Build the results in order from 1 through the requested count.

Hint 3

If the count is zero, the result should be an empty list.

Expected complexity

O(count) time, O(count) extra space

References

This challenge is adapted for CodeUtility. Follow the statement and constraints above.

Learn from others

Community solutions

No published solutions yet. Solve this challenge to share the first one.