java.lang.Object
g1701_1800.s1770_maximum_score_from_performing_multiplication_operations.Solution

public class Solution extends Object
1770 - Maximum Score from Performing Multiplication Operations.<p>Medium</p> <p>You are given two integer arrays <code>nums</code> and <code>multipliers</code> of size <code>n</code> and <code>m</code> respectively, where <code>n >= m</code>. The arrays are <strong>1-indexed</strong>.</p> <p>You begin with a score of <code>0</code>. You want to perform <strong>exactly</strong> <code>m</code> operations. On the <code>i<sup>th</sup></code> operation <strong>(1-indexed)</strong> , you will:</p> <ul> <li>Choose one integer <code>x</code> from <strong>either the start or the end</strong> of the array <code>nums</code>.</li> <li>Add <code>multipliers[i] * x</code> to your score.</li> <li>Remove <code>x</code> from the array <code>nums</code>.</li> </ul> <p>Return <em>the <strong>maximum</strong> score after performing</em> <code>m</code> <em>operations.</em></p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> nums = [1,2,3], multipliers = [3,2,1]</p> <p><strong>Output:</strong> 14</p> <p><strong>Explanation:</strong> An optimal solution is as follows:</p> <ul> <li> <p>Choose from the end, [1,2, <strong>3</strong> ], adding 3 * 3 = 9 to the score.</p> </li> <li> <p>Choose from the end, [1, <strong>2</strong> ], adding 2 * 2 = 4 to the score.</p> </li> <li> <p>Choose from the end, [<strong>1</strong> ], adding 1 * 1 = 1 to the score.</p> </li> </ul> <p>The total score is 9 + 4 + 1 = 14.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> nums = [-5,-3,-3,-2,7,1], multipliers = [-10,-5,3,4,6]</p> <p><strong>Output:</strong> 102</p> <p><strong>Explanation:</strong> An optimal solution is as follows:</p> <ul> <li> <p>Choose from the start, [<strong>-5</strong> ,-3,-3,-2,7,1], adding -5 * -10 = 50 to the score.</p> </li> <li> <p>Choose from the start, [<strong>-3</strong> ,-3,-2,7,1], adding -3 * -5 = 15 to the score.</p> </li> <li> <p>Choose from the start, [<strong>-3</strong> ,-2,7,1], adding -3 * 3 = -9 to the score.</p> </li> <li> <p>Choose from the end, [-2,7, <strong>1</strong> ], adding 1 * 4 = 4 to the score.</p> </li> <li> <p>Choose from the end, [-2, <strong>7</strong> ], adding 7 * 6 = 42 to the score.</p> </li> </ul> <p>The total score is 50 + 15 - 9 + 4 + 42 = 102.</p> <p><strong>Constraints:</strong></p> <ul> <li><code>n == nums.length</code></li> <li><code>m == multipliers.length</code></li> <li><code>1 <= m <= 10<sup>3</sup></code></li> <li><code>m <= n <= 10<sup>5</sup></code></li> <li><code>-1000 <= nums[i], multipliers[i] <= 1000</code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • maximumScore

      public int maximumScore(int[] nums, int[] mult)