For tax purposes I need to trade some stock, generating as small a positive
amount of revenue as possible. I can buy or sell any integer quantity of each stock (I can "sell
short", which means that I can sell more of a stock than I have).
Create a class StockSales that contains a method getAmounts that is given a int[] values,
the prices of the stocks I am willing to trade, and that returns
the amounts of each stock that I should buy or sell. In the return, positive
amounts represent amounts to sell, while negatives represent amounts to buy.
To make the answer unique, choose the amounts in order. Choose each amount to
have the smallest possible absolute value (considering all the earlier
choices). If both the negative and positive amount is available, choose the
positive amount.
|