What is this asking for? I don't understand the goal.


  • 2
    S

    After reading the description I don't understand what a program is supposed to compute to be accepted.

    I understand the array of prices, but how do I know what the maximum profit is without knowing how much I can invest initially? What about selling short before buying any?

    I guess there aren't any transaction fees to consider, but I don't know why it says I have to sell before I buy - if I'm maximizing profit, aren't I buying as much as I can afford, then selling it all right before it goes down?


  • 5
    S

    This is what It means:

    Calculate the maximum profit if you start and end with zero shares,
    only ever own zero shares or one share, buy and sell that one share at
    the best possible times, and don't pay any transaction fees.

    It's a really horribly worded question. I had to read the discussion to understand the goal - which I couldn't do without seeing answers, but it turned out that only the answers expressed the goal clearly. The key restriction that you can only own one share should not be given parenthetically as one possible example. I don't see how anyone figured out the goal just from the description.


  • 0
    S

    I think that's why you should solve ' Best Time to Buy and Sell Stock - I' first, where the definition of 'transaction' was isolated. From my point of view, your rewording is nothing different from the original question except for the 'transaction fee' part, which you really don't need to consider since it is not even mentioned in the original description.


  • 0
    S

    Somehow that didn't occur to me. (Maybe the description should say that.) I thought I should go down the list from easiest to hardest, so I sorted by acceptance rate and started going down the list. But now that I look at it, the description of that problem is also inadequate for largely the same reasons - it parenthetically implies a nonstandard definition of one transaction and uses a single share as an example rather than declaring it as a restriction.


  • 0
    A

    What it really means? if I can buy and sell a stock multiple times i will keep on increasing the profit and there will be no upper bound. I buy A at 1 and sell at 4:profit is 3 I again buy A at 1 and sell at 4 and so on.


  • 0
    S

    @ajak6, The bound really comes from the price data being for a limited time interval. Without the restriction to only owning one share at a time the upper bound over the time for which prices are given would be a function of your initial budget. Offhand I'd say it's a very simple function, just a multiple of that initial budget (a different set of prices would mean a different multiple). With the restriction of only owning one share at a time the upper bound is the solution to this problem.


Log in to reply
 

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