Question: You re working on some more stock - prediction software. The function you re writing accepts an array of predicted prices for a particular stock
Youre working on some more stockprediction software. The function youre writing accepts an array of predicted prices for a particular stock over the course of time.
For example, this array of seven prices:
predicts that a given stock will have these prices over the next seven days. On Day the stock will close at $; on Day the stock will close at $; and so on
Your function should calculate the greatest profit that could be made from a single buy transaction followed by a single sell transaction.
In the previous example, the most money could be made if we bought the stock when it was worth $ and sold it when it was worth $ This yields a profit of $ per share.
Note that we could make even more money if we buy and sell multiple times, but for now, this function focuses on the most profit that could be made from just one purchase followed by one sale.
Now, we could use nested loops to find the profit of every possible buy and sell combination. However, this would be ON and too slow for our hotshot trading platform.
Your job is to optimize the code in C so that the function clocks in at just ON
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
