My 43 ms Java solution using dynamic programming which beats 95%. But I do not know its time complexity. Could anyone help me with that? Thanks!

class Solution { public double findMaxAverage(int[] nums, int k) { int n = nums.length; int[] prefix = new int[n]; // prefix[i] = sum from 0 to i, both inclusive int[] state = new int[n]; // state[i] = length of max average subarray ends at index i; double res = Integer.MIN_VALUE; for (int i = 0; i < n; i++) { prefix[i] = i == 0 ? nums[i] : nums[i] + prefix[i - 1]; state[i] = findLen(i, 1, 10000, prefix, state); // update max average subarray with length >= k if (i < k - 1) { continue; } int len = state[i] >= k ? state[i] : findLen(i, k, 2 * k, prefix, state); int sum = i == len - 1 ? prefix[i] : prefix[i] - prefix[i - len]; res = Math.max(res, (double) sum / len); } return res; } /*/ this method finds the length of max average subarray ends at index i under given length constraints: minLen <= length <= maxLen; /*/ private int findLen(int i, int minLen, int maxLen, int[] prefix, int[] state) { int j = i - minLen; while (j >= 0 && i - j <= maxLen) { int sum = j - state[j] >= 0 ? prefix[j] - prefix[j - state[j]] : prefix[j]; if ((double) sum / state[j] <= (double) (prefix[i] - prefix[j]) / (i - j)) { break; } j -= state[j]; } return i - j; } }Maximum Average Subarray II