Problem Statement
Create a class StockSales that contains a method getAmounts that is given a
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.
Definition
- Class:
- StockSales
- Method:
- getAmounts
- Parameters:
- int[]
- Returns:
- int[]
- Method signature:
- int[] getAmounts(int[] values)
- (be sure your method is public)
Constraints
- values contains between 1 and 50 elements inclusive.
- Each element in values is between 1 and 1,000,000 inclusive.
Examples
{6,12,17}
Returns: { 0, -7, 5 }
The smallest positive revenue is 1. We can trade 0 of the first stock and still achieve this. Choose -7 for the second stock since -7 is the smallest (absolute value) coefficient of 12 that allows us to get revenue of 1: 0*6 + -7*12 + 5*17 = 1.
{10,4}
Returns: { 1, -2 }
The smallest positive revenue is 2. Both {1,-2} and {-1,3} achieve this. {1,-2} is chosen by the tie breaking rule that says to choose the positive amount in preference to the same negative amount. 1*10 + -2*4 = 2, the minimum revenue possible.
{79}
Returns: { 1 }
{60,60,60,60,60,60,60}
Returns: { 0, 0, 0, 0, 0, 0, 1 }
{84,23,46}
Returns: { -3, 1, 5 }
{23,46,84}
Returns: { 1, 5, -3 }
{46,84,23}
Returns: { 0, -3, 11 }
{4,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2}
Returns: { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }
{1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000}
Returns: { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }
{1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000,1000000}
Returns: { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1 }
{17,19,5,13,11,37,59}
Returns: { 0, 0, 0, 0, 0, 8, -5 }
{17,19,37,11,22,110}
Returns: { 0, 0, 3, 0, 0, -1 }
{17,19,37,110,22,11}
Returns: { 0, 0, 3, 0, 0, -10 }
{17,19,37,11,110,33}
Returns: { 0, 0, 3, 0, -1, 0 }
{1000000,499999}
Returns: { -249999, 499999 }
{17,19,11,22,110,37,73,91,52,13,98,4002,32,501,772,999,112,97,95}
Returns: { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -47, 48 }
{17,19,11,22,110,37,73,91,52,13,98,4002,32,501,772,999,112,100,95}
Returns: { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -2, 7, -5 }
{255255,170170,102102,72930,46410,39270,30030}
Returns: { 1, 1, -2, 2, 1, 4, -19 }
{510510, 340340, 204204, 145860, 92820, 78540, 60060}
Returns: { 1, 1, -2, 2, 1, 4, -19 }
{20,4,9,6}
Returns: { 0, 1, 1, -2 }
{ 200000, 240000, 300000, 150000, 400000, 120000, 800000 }
Returns: { 0, 0, 0, -1, 0, 8, -1 }
{ 6, 15, 35 }
Returns: { 1, 2, -1 }
{ 5, 5, 5, 5, 5 }
Returns: { 0, 0, 0, 0, 1 }
{ 6, 10, 15 }
Returns: { 1, 1, -1 }