func FindMaxSubInterval(data []float64, intervalSize int) (T int, preservedInfo float64) {
	n := len(data)
	cumulativeData := make([]float64, n)
	cumulativeData[0] = data[0]
	for i := 1; i < n; i++ {
		cumulativeData[i] = cumulativeData[i-1] + data[i]
	}
	T = 0
	var maxSum int64
	var depth int
	maxSum = 0
	depth = 0
	for i := intervalSize; i < n; i++ {
		var sum int64
		sum = 0
		if (i - intervalSize) == 0 {
			sum = int64(cumulativeData[i])
		} else {
			sum = int64(cumulativeData[i] - cumulativeData[i-intervalSize-1])
		}
		if sum > maxSum {
			maxSum = sum
			T = i - intervalSize
			depth = 0
		} else if sum == maxSum {
			depth++
		} else {
			if depth > 0 {
				T = T + depth/2
				depth = 0
			}
		}
	}
	if depth > 0 {
		T = T + depth/2
	}
	preservedInfo = float64(maxSum) / cumulativeData[n-1]
	return
}
Find the max subinterval with length = intervalSize
It takes O(n) operations to find the interval
package optimalResize
import (
	"image"
	"math"
)
import _ "image/jpeg"
type croppingArea struct {
	region image.Rectangle
	confidenceX float64
	confidenceY float64
}