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.

template  typename 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.

 template  std::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),

  1. start=iterator to buying element
  2. end=iterator to selling element

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!