### Question:
StockPrices { public static int findBenefit(int[] prices) { if (prices == null || prices.length < 2) { throw new IllegalArgumentException("Prices cannot be null or with length less than 2"); } int[] min = new int[prices.length]; int[] max = new int[prices.length]; min[0] = prices[0]; max[prices.length - 1] = prices[prices.length - 1]; for (int i = 1; i < prices.length; i++) { min[i] = min(min[i - 1], prices[i]); max[prices.length - 1 - i] = max(max[prices.length - i], prices[prices.length - 1 - i]); } int benefit = MIN_VALUE; for (int i = 1; i < max.length; i++) { benefit = max(benefit, max[i] - min[i - 1]); } return benefit; }  static int findBenefit(int[] prices);  }### Answer:
@Test(expected = IllegalArgumentException.class) public void testFindBenefitNullArray() { findBenefit(null); }
@Test(expected = IllegalArgumentException.class) public void testFindBenefitZeroArray() { findBenefit(new int[0]); }
@Test(expected = IllegalArgumentException.class) public void testFindBenefitOneElementArray() { findBenefit(new int[]{1}); }
@Test public void testFindBenefit1() { int actual = findBenefit(new int[]{5, 1, 4, 6, 7, 8, 4, 3, 7, 9}); assertThat(actual, is(8)); }
@Test public void testFindBenefit2() { int actual = findBenefit(new int[]{2, 100, 1, 2}); assertThat(actual, is(98)); }
@Test public void testFindBenefit3() { int actual = findBenefit(new int[]{1, 2, 2, 100}); assertThat(actual, is(99)); }
@Test public void testFindBenefit4() { int actual = findBenefit(new int[]{1, 2, 3, 4, 5, 6, 7, 8, 9, 10}); assertThat(actual, is(9)); }
@Test public void testFindBenefit5() { int actual = findBenefit(new int[]{3, 2, 1}); assertThat(actual, is(-1)); }