Leetcode Problem 2898. Maximum Linear Stock Score

2898. Maximum Linear Stock Score

Leetcode Solutions

Decoupling with HashMap

  1. Initialize an empty HashMap to store the sum of prices for each unique prices[i] - i value.
  2. Iterate over the prices array.
  3. For each price prices[i], calculate the key as prices[i] - i.
  4. Add the price to the sum for the corresponding key in the HashMap.
  5. Keep track of the maximum sum encountered during the iteration.
  6. After iterating through all prices, return the maximum sum.
UML Thumbnail

Brute Force with Optimization

Ask Question

Programming Language
image/screenshot of info(optional)
Full Screen
Loading...

Suggested Answer

Answer
Full Screen
Copy Answer Code
Loading...