oneby7

Foundations Loops

589. Multiplication Table

Easy

Given an integer n and a count k, return the first k multiples of n. These are n × 1, n × 2, and so on up to n × k, in that order.

This is the multiplication table of n. The answer always holds exactly k values.

Example 1

Input: n = 6, k = 5

Output: [6,12,18,24,30]

Explanation: The values are 6 × 1 = 6, 6 × 2 = 12, and so on up to 6 × 5 = 30.

Example 2

Input: n = -4, k = 3

Output: [-4,-8,-12]

Explanation: The multiples of a negative number are negative too. They keep the order of the table, from −4 × 1 down to −4 × 3.

Example 3

Input: n = 1000000000, k = 3

Output: [1000000000,2000000000,3000000000]

Explanation: The last value, 3 × 109, is too large for a 32-bit integer.

Check your understanding

Work out the answer for this input before you write any code.

n = 7, k = 4

Constraints

  • -109 ≤ n ≤ 109
  • 1 ≤ k ≤ 105

Clarifying questions

What you would ask an interviewer before writing any code.

Hints

Interview follow-ups

Runs in your browser
Code
Runs in your browser for now · some things may not work as expectedLn 1, Col 1

Article

Send feedback

Thank you for helping. We read every report and fix what is wrong.

How do you feel about oneby7?

Sign in to oneby7

Keep your progress, your streak and your code, on any device.

New here? This creates your account too.