Difference between this question and CLRS 4.1

  • 3

    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)

  • 0

    Could you please describe the problem statement in section 4.1 of CLRS here?

  • 0

    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 Sum(Ak, k=i..j).

    Please take note that in this problem (Best Time to Buy and Sell Stock II) you are not limited to one transaction.

Log in to reply

Looks like your connection to LeetCode Discuss was lost, please wait while we try to reconnect.