Maximum Score from Performing Multiplication Operations

Advanced

Welcome to this exciting code challenge where you'll help a magician maximize scores from his magic boxes! Every box holds a treasure with a magical multiplier.

You're given a list of integers, nums, which represents treasures, and another list of integers, multipliers, representing the magical powers of each box. Your task is to maximize the total score by multiplying each magic box with one of the treasures, either from the start or the end of the list. The number of magic boxes is always equal to the length of the multipliers list.

Here's the trick: You can only perform the multiplication operations one by one and must choose the treasures from either the start or end of the list!

Rules:

  • You can select treasures from either the start or the end of the list nums, but once a treasure is used, it's removed from the list.
  • Multipliers must be used in order.
  • You must use each multiplier exactly once.

Write a function max_score that will return the maximum score possible.

Examples:

max_score([1, 2, 3], [3, 2, 1]) # Output: 14

Explanation:

  • Operation 1: Multiply 3 (multiplier) with 3 (nums end) → 3 * 3 = 9
  • Operation 2: Multiply 2 with 2 (nums middle) → 2 * 2 = 4
  • Operation 3: Multiply 1 with 1 (nums start) → 1 * 1 = 1
  • Total Score: 9 + 4 + 1 = 14
max_score([-5, -3, -3, -2, 7, 1], [1, -2, 3]) # Output: 32

Explanation:

  • Operation 1: Multiply 1 with 1 (nums end) → 1 * 1 = 1
  • Operation 2: Multiply -2 with -5 (nums start) → -2 * -5 = 10
  • Operation 3: Multiply 3 with 7 (nums end) → 3 * 7 = 21
  • Total Score: 1 + 10 + 21 = 32

Challenge your magic and find the correct magic score!

Geek
Inputs

Arg 1:

[1,2,3]

Arg 2:

[3,2,1]
Expected Output
14
Actual Output
Maximum Score from Performing Multiplication Operations [advanced] | Coding for Kids