Home | Projects | Notes > Problem Solving > EPI - 6.7. Buy and Sell a Stock Once

EPI - 6.7. Buy and Sell a Stock Once

 

Solutions in C++

Solution 1

The key is to compute the maximum profit by computing the difference of the current entry with the minimum value seen so far as we iterate through the array.

Complexity Analysis:

Solution:

 

Solutions in C

Solution 1

The key is to compute the maximum profit by computing the difference of the current entry with the minimum value seen so far as we iterate through the array.

Complexity Analysis:

Solution: