Maximum Score from Performing Multiplication Operations - Problem

You are given two 0-indexed integer arrays nums and multipliers of size n and m respectively, where n >= m.

You begin with a score of 0. You want to perform exactly m operations. On the i-th operation (0-indexed) you will:

  • Choose one integer x from either the start or the end of the array nums.
  • Add multipliers[i] * x to your score.
  • Remove x from nums.

Return the maximum score after performing m operations.

Input & Output

Example 1 — Basic Case
$ Input: nums = [1,2,3], multipliers = [3,2,1]
Output: 14
💡 Note: Optimal picks: Take 3 (right) → score = 3×3 = 9. Take 2 (right) → score = 9 + 2×2 = 13. Take 1 (left) → score = 13 + 1×1 = 14. Total: 14
Example 2 — All From Left
$ Input: nums = [-5,-3,-3,-2,7,1], multipliers = [-10,-5,3,4,6]
Output: 102
💡 Note: Take from left: -5×(-10)=50, -3×(-5)=15, -3×3=-9, -2×4=-8, 7×6=42. Total: 50+15-9-8+42 = 90. But optimal strategy gives 102.
Example 3 — Mixed Strategy
$ Input: nums = [1], multipliers = [5]
Output: 5
💡 Note: Only one element and one multiplier: 1×5 = 5

Constraints

  • n == nums.length
  • m == multipliers.length
  • 1 ≤ m ≤ 103
  • m ≤ n ≤ 105
  • -1000 ≤ nums[i], multipliers[i] ≤ 1000

Visualization

Tap to expand
Maximum Score from Multiplication Operations123nums array321multipliersPick from ends only14Optimal picks: 3→2→1 gives score 14
Understanding the Visualization
1
Input Arrays
nums=[1,2,3] and multipliers=[3,2,1]
2
Pick Strategy
Choose from left or right end, multiply with current multiplier
3
Maximum Score
Find optimal sequence to maximize total score
Key Takeaway
🎯 Key Insight: Since we can only pick from ends, each state depends on how many we've taken from left vs right, creating perfect DP substructure
Asked in
Facebook 15 Google 12 Amazon 8
98.0K Views
Medium Frequency
~35 min Avg. Time
1.8K Likes
Ln 1, Col 1
Smart Actions
💡 Explanation
AI Ready
💡 Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen