Search⌘ K
AI Features

Feature #4: Maximum Profit

Explore how to determine the maximum profit from an array representing stock price changes over consecutive days. Understand the use of currentMax and globalMax variables to track sums of sub-arrays, enabling you to solve maximum sub-array sum problems efficiently. By the end, you'll grasp coding solutions with linear time and constant space complexities.

Description

We have now extracted the stock increase and decrease percentages over a number of consecutive days. This will be represented as an array of numbers, one for each consecutive day, holding the increase or decrease in stock price on the given day. We can use this data to find the maximum profit that could have been made for the given time period. Sometimes, the maximum profit might be negative, indicating a period of minimum loss. For simplicity and to avoid fractional values, we are rounding the increase and decrease percentages to their nearest value.

We’ll be provided with an array of positive and negative integers. The indexes will indicate the day number and the integer value will indicate ...