Tutorialarrayimplementation
A Row of the Times Table
- Memory limit
- 256 MB
- Correctness time limit
- 10000 ms
- Solvers
- 0
Given integers n and k, return the array [n × 1, n × 2, …, n × k] in that order. Its length is k.
Examples
| n | k | result |
|---|---|---|
2 | 5 | [2, 4, 6, 8, 10] |
7 | 1 | [7] |
12 | 3 | [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
-
n -
k
Expected complexity
- Time
- O(K)
- Space
- O(N)
Examples
| n | k | Expected |
|---|---|---|
2 | 5 | [2,4,6,8,10] |
7 | 1 | [7] |
12 | 3 | [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
| Language | Efficiency time limit | |
|---|---|---|
| C (GCC, gnu17) | 200 ms | estimated |
| C++ (GCC, gnu++23) | 200 ms | derived |
| Python 3.13 | 1000 ms | derived |
| Java 25 | 1000 ms | derived |
| Kotlin 2.4 (JVM) | 1200 ms | estimated |
| C# 14 (.NET 10) | 1200 ms | estimated |
Test groups
| Group | Weight | Tests | Visibility |
|---|---|---|---|
| sample | 0 | 3 | inputs and outputs |
| correctness | 100 | 11 | verdict only |