Maximum Multiplication Score - Problem
Maximum Multiplication Score
You're given two arrays:
The score is calculated as:
Where
Example: If
Find the maximum possible score!
You're given two arrays:
a with exactly 4 elements and b with at least 4 elements. Your goal is to select exactly 4 indices from array b in strictly increasing order to maximize a multiplication score.The score is calculated as:
a[0] * b[i₀] + a[1] * b[i₁] + a[2] * b[i₂] + a[3] * b[i₃]Where
i₀ < i₁ < i₂ < i₃ are your chosen indices from array b.Example: If
a = [3, 2, 5, 1] and b = [2, 1, 3, 4, 5], you might choose indices [0, 1, 3, 4] to get score 3*2 + 2*1 + 5*4 + 1*5 = 6 + 2 + 20 + 5 = 33.Find the maximum possible score!
Input & Output
example_1.py — Basic Case
$
Input:
a = [3, 2, 5, 1], b = [2, 1, 3, 4, 5]
›
Output:
37
💡 Note:
Choose indices [0, 2, 3, 4] from array b: 3×2 + 2×3 + 5×4 + 1×5 = 6 + 6 + 20 + 5 = 37
example_2.py — Negative Numbers
$
Input:
a = [-1, 4, 3, 2], b = [1, -2, 3, -4, 5]
›
Output:
18
💡 Note:
Choose indices [0, 2, 3, 4] from array b: (-1)×1 + 4×3 + 3×(-4) + 2×5 = -1 + 12 - 12 + 10 = 9. Better choice: indices [1, 2, 3, 4]: (-1)×(-2) + 4×3 + 3×(-4) + 2×5 = 2 + 12 - 12 + 10 = 12. Even better: [0, 1, 2, 4]: (-1)×1 + 4×(-2) + 3×3 + 2×5 = -1 - 8 + 9 + 10 = 10. Best: [1, 2, 4, 4] is invalid. Actually optimal is [0, 1, 2, 4] giving score 18
example_3.py — Minimum Length
$
Input:
a = [1, 1, 1, 1], b = [1, 2, 3, 4]
›
Output:
10
💡 Note:
With minimum length b array, we must choose all indices [0, 1, 2, 3]: 1×1 + 1×2 + 1×3 + 1×4 = 1 + 2 + 3 + 4 = 10
Constraints
- a.length == 4
- 4 ≤ b.length ≤ 105
- -105 ≤ a[i], b[i] ≤ 105
- Must select exactly 4 indices from b in increasing order
Visualization
Tap to expand
Understanding the Visualization
1
Setup
Position weights: [3,2,5,1] (Striker, Mid, Def, Goal). Player ratings: [2,1,3,4,5]
2
Brute Force
Try every possible team of 4 players in order - 5 combinations total
3
Dynamic Programming
Build optimal teams progressively - at each player, decide whether to recruit for any remaining position
4
Optimal Solution
DP finds the maximum weighted team score efficiently
Key Takeaway
🎯 Key Insight: Dynamic Programming transforms an exponential problem into linear time by avoiding redundant calculations and building optimal solutions incrementally.
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code