Question: You are given an input array A with n positive elements. Each element is the value of a stock at that point (time). Assuming are
You are given an input array A with n positive elements. Each element is the value of a stock at that point (time). Assuming are given this future information you need to decide when to buy and sell the stock to make maximum profit (i.e. sell - buy).
1.
Implement, using divide and conquer, the function below which returns the maximum possible profit.
templatetypename Iter::value_type max_profit(Iter start, Iter end) { return 0; }
2.
Implement, using divide and conquer, the function below which returns a pair of iterators pointing to the buying/selling values respectively.
templatestd::pair max_profit_interval(Iter start, Iter end) { return std::make_pair(start,end); }
3.
Implement the function below which returns the indices of the buying selling values, given:
1.begin=iterator to the beginning of the container (e.g. vector),
- start=iterator to buying element
- end=iterator to selling element
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
