public static int checkForDone() {
        periodCount = 0;
        int ans = 0;
        for (int T = 2; T <= maxExtremums && T * 2 <= curExtremumCount; T += 2) {
            for (int i = T; i < curExtremumCount; i++) {
                if (Math.abs(extremums[curExtremumCount - 1 - i]
                        - extremums[curExtremumCount - 1 - (i % T)]) < EPS) {
                    if (periodCount < (i - T + 1) / T) {
                        periodCount = (i - T + 1) / T;
                        ans = T;
                        if (periodCount >= maxPeriodsNeeded) {
                            return ans;
                        }
                    }
                } else {
                    break;
                }
            }
        }
        return ans;
    }