AlgoFrames

Fill the hold, sold and rest arrays

Warm-up · Trace the algorithm · about 6 min

Prices for six days are [2, 1, 4, 5, 2, 9]. After a sale you must rest one day. Follow the three state arrays and answer each question before the step plays.

Example 1

Input:

{"values":[2,1,4,5,2,9]}

Output:

10

Constraints

  • The trace uses the prices shown.
  • Hold at most one share at a time.

Learn the idea first: State machine DP: stock problems, a visual lesson.

More State machine DP: stock problems problems