Funcia
Tutorialarrayimplementation

A Row of the Times Table

Memory limit
256 MB
Correctness time limit
10000 ms
Solvers
0
0

Given integers n and k, return the array [n × 1, n × 2, …, n × k] in that order. Its length is k.

Examples

nkresult
25[2, 4, 6, 8, 10]
71[7]
123[12, 24, 36]

Example 1 — 2×1 through 2×5.

Example 2 — With k = 1 there is one element.

Example 3 — 12, 24, 36.

This is a tutorial problem: there are no performance tests, just return the correct value.

Function signature

solution(n: int, k: int) → int[]

Constraints

  • 1≤1 \le n ≤1,000\le 1{,}000
  • 1≤1 \le k ≤100\le 100

Expected complexity

Time
O(K)
Space
O(N)

Examples

nkExpected
25[2,4,6,8,10]
71[7]
123[12,24,36]

Hint

Hint

Build an array of length k: for i from 1 to k, store or append n * i (append in Python, push_back in C++, result[i - 1] = n * i with new int[k] in Java).

Time limits per language

LanguageEfficiency time limit
C (GCC, gnu17)200 msestimated
C++ (GCC, gnu++23)200 msderived
Python 3.131000 msderived
Java 251000 msderived
Kotlin 2.4 (JVM)1200 msestimated
C# 14 (.NET 10)1200 msestimated

Test groups

GroupWeightTestsVisibility
sample03inputs and outputs
correctness10011verdict only
Loading editor…
Log in to run or submit code.

No result yet. Run or submit your code.