MarblesThreeBaskets { public int minStep(int[] marbles) { Arrays.sort(marbles); int sum = IntStream.of(marbles).sum(); int[][][] dp = new int[sum][sum][sum]; if (sum % 3 != 0) { return -1; } for(int i = 0; i < sum; i++) { for(int j = 0; j < sum; j++) { for(int k = 0; k < sum; k++) { if (i == j && j == k) { dp[i][j][k] = 0; } else { dp[i][j][k] = -1; } } } } return minStep(marbles, dp); }  int minStep(int[] marbles); int minStep(int[] marbles, int[][][] dp);  }
@Test(dataProvider = "marbles") public void test(int[] marbles, int step) { assertEquals(step, new MarblesThreeBaskets().minStep(marbles)); }