2898. Maximum Linear Stock Score
ArrayHash Table
Hints
Hint 1
Let's look at the condition as:
prices[indexes[i]] - indexes[i] == prices[indexes[j]] - indexes[j].Hint 2
So now we define a new array named
group and is constructed as group[i] = prices[i] - i.Hint 3
A subarray of
prices is linear if they belong to the same group.Hint 4
Since all elements are positive, if we choose some index
i, the optimum way is to choose all elements from group[i].Hint 5
So for each group, we calculate the sum of its prices and the answer would be the maximum sum over all groups.
Preparing judge…