Problem · Array

Get Maximum Score

Learn this problem
MediumAtlassian logoAtlassianFULLTIMEOA

Problem 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[]) → long

Examples

Example 1

stockPrice = [1,5,3,7,8]return = 20

Choose 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 <= 200000
  • 1 <= stockPrice[i] <= 10^9
  • The answer fits a signed long.

More Atlassian problems

drafts saved locally
public long getMaximumScore(int[] stockPrice) {
  // Write your code here.
}
stockPrice[1,5,3,7,8]
expected20
checking account