For test case [3,2,6,5,0,3] I got a better result 6 (buy, buy, sell, sell, nothing, nothing) instead of expected 4.

  • 0


    Anybody can help me understand what I do not understand?

    One of the test cases is: [3,2,6,5,0,3] and the expected output is 4.

    Now, let's assume that 'b' means buy, 's' means sell, and 'n' means do nothing. So if we have the following scenario:


    My initial profit is 0.

    action    profit     why
    b         -3          -3
    b         -5          -2
    s          1          +6
    s          6          +5
    n          6          (just pass)
    n          6          (just pass)

    So I end up with a better profit 6 rather than what is expected 4.

    Do I get it wrong? Why?


  • 1

    You are

    only permitted to complete at most one transaction

    but you complete two.

  • 0

    Oh, thanks. I see. I thought that I have an option to buy, sell or do nothing for each priced stock.

  • 0

    Even you could buy or sell or do nothing each time,the result should be 7(nothing , buy, sell, nothing, buy , sell)

Log in to reply

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