Highest Profit
You have the ability to accurately predict the price of a specific stock for the next N days. Your goal is to maximize your profit using this information, but you're restricted to performing only one transaction per day: buying one share, selling one share, or doing nothing. At the start, you don't own any shares, and you can only sell shares if you own them. By the end of the N days, you must again own zero shares, and your objective is to achieve the highest possible profit.
Example 1
Input:
[10, 5, 4, 7, 9, 12, 6, 2, 10]
Output:
20
main.cpp
C++
Demandez à l'IA
Demandez à l'IA
Posez n'importe quelle question ou essayez l'une des questions suggérées pour commencer notre discussion