Maximum Multiplication Score - Problem

You are given an integer array a of size 4 and another integer array b of size at least 4.

You need to choose 4 indices i₀, i₁, i₂, i₃ from array b such that i₀ < i₁ < i₂ < i₃.

Your score will be equal to a[0] * b[i₀] + a[1] * b[i₁] + a[2] * b[i₂] + a[3] * b[i₃].

Return the maximum score you can achieve.

Input & Output

Example 1 — Basic Case
$ Input: a = [3,2,-1,1], b = [5,-3,4,2,-1,6]
Output: 26
💡 Note: Choose indices [0,3,4,5]: 3×5 + 2×2 + (-1)×(-1) + 1×6 = 15 + 4 + 1 + 6 = 26
Example 2 — Negative Values
$ Input: a = [-1,4,5,2], b = [2,1,8,3,6]
Output: 68
💡 Note: Choose indices [1,2,3,4]: (-1)×1 + 4×8 + 5×3 + 2×6 = -1 + 32 + 15 + 12 = 58
Example 3 — Minimum Size
$ Input: a = [1,2,3,4], b = [5,6,7,8]
Output: 70
💡 Note: Must use all indices [0,1,2,3]: 1×5 + 2×6 + 3×7 + 4×8 = 5 + 12 + 21 + 32 = 70

Constraints

  • a.length == 4
  • 4 ≤ b.length ≤ 105
  • -105 ≤ a[i], b[i] ≤ 105

Visualization

Tap to expand
Maximum Multiplication Score ProblemArray a (weights)32-110123Array b (choose 4)5-342-16012345Selected indices: [0, 3, 4, 5]Score = 3×5 + 2×2 + (-1)×(-1) + 1×6= 15 + 4 + 1 + 6Maximum Score: 26
Asked in
Google 15 Amazon 12 Microsoft 8 Meta 6
32.8K Views
Medium Frequency
~25 min Avg. Time
840 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