The market prediction algorithm helps one to know the share price for apple over the next N days. Each day, you can eit
Posted: Thu May 05, 2022 12:46 pm
The market prediction algorithm helps one to know the share price for apple over the next N days. Each day, you can either buy one share, or sell one share or do nothing at all. You can keep only one share with you, and therefore you can buy just one item and to buy the next time you must sell what you have first.
Given N days and the price of Apple on each day, what is the maximum profit you can make with an optimum trading strategy?
keep in mind that you cannot buy and sell on the same day and if you don't have any item you can't sell anything.
Input format
First line contains a single integer 'N' and next line contains 'N' space separated integers having the price of Apple on each day from 1st day to Nth day. ( left to right)
output format:
An integer representing the maximum amount of profit you can make.
Example :
Input:
4
2 4 6 3
Output
4
write a C++ or java program on this need the answer asap please
Given N days and the price of Apple on each day, what is the maximum profit you can make with an optimum trading strategy?
keep in mind that you cannot buy and sell on the same day and if you don't have any item you can't sell anything.
Input format
First line contains a single integer 'N' and next line contains 'N' space separated integers having the price of Apple on each day from 1st day to Nth day. ( left to right)
output format:
An integer representing the maximum amount of profit you can make.
Example :
Input:
4
2 4 6 3
Output
4
write a C++ or java program on this need the answer asap please