The problem being addressed in section 4.1 of CLRS is very much similar to this one. But when I applied "maximum subarray" , solution did not get accepted. I understand that maximum subarray maximizes contiguous sum. But I do not understand how to differentiate this problem from CLRS' problem statement.
update: page from the book
if you are not able to find the page, here is the pdf copy of book
page 89 (for pdf viewer)
(for printed book page no. 68)
This is a totally different problem compared to the "Maximum Subarray" problem.
In the original "Best Time to Buy and Sell Stock" problem, you are required to maximize the profit
Aj - Ai, while the "Maximum Subarray" problem maximizes
Please take note that in this problem (Best Time to Buy and Sell Stock II) you are not limited to one transaction.