prices, where prices[i] is a stock's price on day i (days are 0-based). Pick some days, at least one, so that between any two consecutive picked days the price grew by exactly as much as the number of days that passed. In other words, for consecutive picked days i < j it must hold that prices[j] - prices[i] == j - i.
The score of a pick is the sum of the prices on the picked days. Return the highest score possible.
A single picked day is a valid pick too.prices=[3, 9, 5, 6, 10, 8] → 22
Pick days 0, 2, 3 and 5 with prices 3, 5, 6, 8. From day 0 to day 2 the price rose by 2 over 2 days, from 2 to 3 by 1 over 1 day, from 3 to 5 by 2 over 2 days. The total is 22.
prices=[7, 4, 1] → 7
The price only falls, so no two days can go together. The best is the single day priced 7.
prices=[2, 3, 4, 20, 6] → 20
prices=[3, 9, 5, 6, 10, 8]
22
Run checks the first 3 tests in your browser. Submit checks all 149 tests on the server, hidden ones included.