Description
Solutions
Future Stock Prices
π€ INTERNπRELATED PROBLEMS
Given an unordered list of future stock prices, what is the maximum amount of profit that you could generate from a starting amount of $1,000.00
Rules:
Function Description
Complete the function calculateMaxProfit
in the editor.
calculateMaxProfit
has the following parameter:
String[] stockPrices
: an array of stock price information
Returns
int: the maximum profit rounded to the nearest dollar
Example 1:
Input: stockPrices = ["CSCO,10/18/2024,41.89", "AMZN,10/10/2024,113.67", "AMZN,10/18/2024,120.5", "CSCO,10/10/2024,43.12"]
Output: 60
Explanation:Buy 8.797 AMZN @ $113.67 on 10/10/2024 and sell @ $120.5 on 10/18/2024. Profit = $60
Example 2:
Input: stockPrices = ["IBM,12/01/2023,132.05", "IBM,12/03/2023,135.19", "IBM,12/18/2023,134.07", "AAPL,12/01/2023,187.19", "AAPL,12/04/2023,164.33", "AAPL,12/20/2023,180.94", "AAPL,12/21/2023,179.65", "GOOG,12/01/2023,116.41", "GOOG,12/07/2023,111.36", "GOOG,12/19/2023,112.19"]
Output: 127
Explanation:Buy 7.573 IBM @ $132.05 on 12/1/2023 and sell @ 135.19 on 12/3/2023. Buy 6.230 AAPL on 12/4/2023 @ $164.33 and sell on 12/20/2023 @ $180.94. Profit = $127
Constraints:
ππ

Related Problems
Testcase
Result
Case 1
input:
output: