You are viewing a single comment's thread. Return to all comments →
Java 8 solution (passes all test cases):
static int maxSubsetSum(int[] arr) { int[] dynArray = new int[arr.length + 1]; dynArray[0] = 0; dynArray[1] = arr[0]; List<Integer> toCompare = new ArrayList<Integer>(); for (int i = 2; i <= arr.length; i++) { toCompare = new ArrayList<Integer>(); toCompare.add(dynArray[i-1]); toCompare.add(arr[i-1]); toCompare.add(dynArray[i-2] + arr[i-1]); dynArray[i] = Collections.max(toCompare); } Arrays.sort(dynArray); return Math.max(dynArray[arr.length],0); }
Seems like cookies are disabled on this browser, please enable them to open this website
Max Array Sum
You are viewing a single comment's thread. Return to all comments →
Java 8 solution (passes all test cases):