Maximum Weighted End-Pick Score
Problem statement
Choose exactly multipliers.length numbers from nums. At step t, remove either the first or the last remaining number, multiply it by multipliers[t], and add the product to your score.
The multiplier order is fixed. Every multiplier must be used, even if doing so decreases the score. Return the largest possible total score.
When all multipliers equal one, this is the base task of choosing k endpoint numbers to maximize their sum. The weighted task preserves that case and the interview follow-up in one contract.
Function
maximumEndPickScore(nums: int[], multipliers: int[]) → intExamples
Example 1
nums = [1,2,3]multipliers = [3,2,1]return = 14Choose 3, then 2, then 1: 3*3 + 2*2 + 1*1 = 14.
Example 2
nums = [9,1,2,8]multipliers = [1,1]return = 17The base case chooses 9 and 8 for total 17.
Constraints
1 <= multipliers.length <= min(nums.length, 400).1 <= nums.length <= 20000.-1000 <= nums[i], multipliers[t] <= 1000.