DEV Community

loading...

Discussion on: Daily Challenge #228 - Best Profit in Single Sale

Collapse
blazephoenix profile image
Tanmay Naik

How is the last output -1? Shouldn't it be 9?

Collapse
vidit1999 profile image
Vidit Sarkar

Here I represented the loss with negative number.

For the last case the vector is sorted in descending order. So there is no way user will make any profit. The minimum loss is 1 (i.e. buy the item at price 5 and sell it at price 4).

Remember you have to buy the item first and then sell it.