Please explain the problem more clearly!!!

  • 96

    "If you were only permitted to complete at most one transaction (ie, buy one and sell one share of the stock), design an algorithm to find the maximum profit."

    I misunderstood the above sentence as at most either buy or sell one share of stock on a single day. In that case, I buy at a local minimum price and sell it at a local maximum to reach a maximum total profit.

    Please consider changing it to something like the following:

    If you were only permitted to complete at most one buy and at most one sell during the whole period of days, design an algorithm such that your profit, i.e., sell price minus buy price, is maximized. Note that you can only not sell a stock before you buy one.

    For example:

    [1,2,3,4] ==> returns 3 (buy at 1 and sell at 4)

    [4,3,2,1] ==> returns 0 (don't buy)

    [4,10,25,2,10] ==> returns 21 (buy at 4 and sell at 25)

  • 4

    Same here, I don't know anything about stocks, nor I want to learn just to understand this problem, please be more verbose.

    Another thing that might be worth doing is putting the whole problem into past tense (what was time when I could've achieved the most profit), or into magic future where you can predict stock prices.

  • 1

    Good explanation for the understanding the problem!

  • 1

    Two others suggestions. First, the title of the question because the output is the max potential profit and not the 'best time'. Second, they should replace the phrase 'design an algorithm' with something like 'compute the optimal profit', since in a trading context an algorithm is usually understood to be an online algorithm (and this question is an offline question).

  • 0

    You are correct, the problem description is inaccurate. Your wording is freaking spot on. surprised leetcode hasnt fixed it yet.

  • 0

    Had the same confusion when I first encoutered BuyAndSell II, which I did before this one.

  • 0

    Yes! I have the same confusion with you. The question is not clear!

  • 0

    3q for your explain!

  • 0

    A clear explanation for my frustration. The examples given at the problem description itself is very ambiguous.

  • 0

    Yes! And the biggest problem is when they explained why we must not choose (7,1). The word after would be suffiscent

  • 0

    @ElementNotFoundException Thank you!! Could not understand the problem as written.

Log in to reply

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