Here you can find the source of max_val_subsequence(int[] vals)
static int[] max_val_subsequence(int[] vals)
//package com.java2s; //License from project: Apache License public class Main { /**/*from w w w . java 2 s . c om*/ * Returns the sum and bounds of the maximum subsequence sum within bounds * returned in the form {sum, start_index, end_index}; */ static int[] max_val_subsequence(int[] vals) { int a = 0, b = 1, max = Integer.MIN_VALUE; int i = 0, sum = 0; for (int j = 0; j < vals.length; ++j) { sum += vals[j]; if (max < sum) { max = sum; a = i; b = j + 1; } if (sum <= 0) { sum = 0; i = j + 1; } } return new int[] { max, a, b }; } }