Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.

book
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

main.cpp

C++

Chieda ad AI

expand

Chieda ad AI

ChatGPT

Chieda pure quello che desidera o provi una delle domande suggerite per iniziare la nostra conversazione

some-alt