Menu

Sign in to track your progress and unlock all features.

Theme style

Log in

Problem No 21

Build Multiplication Table

Medium

17 minute session

Summary

Generate a rows x cols multiplication table (1-based indices) as a list of lists.

Problem statement

Write build_multiplication_table(rows, cols) that returns a list of rows lists, each containing cols integers. The value at row i and column j should be (i+1) * (j+1), using 1-based multiplication factors. If rows or cols are zero, return an empty list.

Task

Practice nested loops and building 2D lists row by row.

Examples

3x3 table

Input

build_multiplication_table(3, 3)

Output

[[1, 2, 3], [2, 4, 6], [3, 6, 9]]

Explanation

Rows and columns are 1-based. Row 2 column 3 = 2 * 3 = 6.

Input format

Two integers: rows and cols (each >= 0).

Output format

A list of lists representing the multiplication table.

Constraints

rows and cols are non-negative integers. Aim for O(rows * cols) time and space.

Samples

Sample input 0

build_multiplication_table(1, 4)

Sample output 0

[[1, 2, 3, 4]]

Explanation 0

Single row with columns 1..4.

Code editor
Loading editor…

AI assistant

Ask me anything!

Need help? I can explain the core idea behind this problem, review your current code, and give targeted hints. Use “Teach Theory” for the concept, “Get AI hint” for a quick scaffold nudge, or ask a specific question below.

Chat history is temporary and will not be saved.

03:41 AM

Free preview includes 1 Teach Theory response and 1 AI hint per unlocked preview lesson.