Problem · Array
Get Maximum Score
Learn this problemProblem statement
Given daily stock prices in stockPrice, choose a non-empty subsequence of day indices in increasing order.
The subsequence is balanced when every consecutive chosen pair previous and current satisfies stockPrice[current] - stockPrice[previous] = current - previous. Its score is the sum of prices on the chosen days.
Return the maximum possible score of a balanced subsequence.
Function
getMaximumScore(stockPrice: int[]) → longExamples
Example 1
stockPrice = [1,5,3,7,8]return = 20Choose indices [1,3,4], giving prices [5,7,8]. Their differences equal the corresponding index differences, and the score is 5 + 7 + 8 = 20.
Constraints
1 <= stockPrice.length <= 2000001 <= stockPrice[i] <= 10^9- The answer fits a signed
long.