PracticeArrays

Level Combo Score Multiplier

EasyArraystraversalnested iterationboundary handling Time not estimated Not started

Context

In a gaming challenge, each player has score bonuses recorded by level and move. A second record gives the matching multiplier for each position. Build the combined score record by multiplying values that occupy the same level and move position.

Problem

Implement a function that combines two nested integer sequences. Pair their outer lists in order, then pair entries within each corresponding inner list in order. For every aligned pair, place the product in the matching position of the result. Stop an outer pairing when either input has no more outer lists, and stop an inner pairing when either corresponding inner list has no more entries. Preserve the order and nested structure of all processed pairs, including empty inner lists. Negative values and zero are valid and must be handled by ordinary integer multiplication.

Examples

Example 1
Input: multipliers = [[10, 20, 30], [2, 4]]score_values = [[2, 4, 6], [3, 5]]
Output: [[20, 80, 180], [6, 20]]
Explanation: The first outer pair produces 2×10, 4×20, and 6×30, while the second produces 3×2 and 5×4, so the executed result is [[20, 80, 180], [6, 20]].
Example 2
Input: multipliers = [[3, 4, 9], [], [6]]score_values = [[7, -2, 0], [], [5, 8]]
Output: [[21, -8, 0], [], [30]]
Explanation: The executed result is [[21, -8, 0], [], [30]]: the first row multiplies aligned values, the empty aligned pair remains empty, and the last row uses its one aligned pair.
Example 3
Input: multipliers = [[10, 20], [2], [9], [8]]score_values = [[1, 2, 3], [4], [5, 6]]
Output: [[10, 40], [8], [45]]
Explanation: The executed result is [[10, 40], [8], [45]] because each processed row contains products only through the first inner exhaustion, and the extra outer list is not processed.

Constraints

  • 0 <= len(score_values) <= 40
  • 0 <= len(score_values[i]) <= 40 for every i
  • -1000000 <= score_values[i][j] <= 1000000 for every i, j
  • 0 <= len(multipliers) <= 40
  • 0 <= len(multipliers[i]) <= 40 for every i
  • -1000000 <= multipliers[i][j] <= 1000000 for every i, j
  • Types: score_values is int[][], multipliers is int[][]; result is int[][]

Function signature

def combine_level_scores(score_values: list[list[int]], multipliers: list[list[int]]) -> list[list[int]]
score_values list[list[int]]
Nested integer values for each level and move.
multipliers list[list[int]]
Nested integer multipliers aligned with the score values.
returns list[list[int]]
A nested integer sequence containing the products of aligned entries, with outer and inner pairing stopped at the shorter available sequence.

Adapted from MBPP problem task_445 (CC BY 4.0). Rewritten, extended and verified by Iksha.

Approved · cc030r1-abs_899_v214 execution-verified tests
Code
Saved
Checking environment…Python SandboxLn 1, Col 1