title: Find Maximum Average Subarray Of K Length 1
signature: class Solution {
  
      public Integer findMaximumAverageSubarrayOfKLength1(ArrayList<Integer> arr, Integer n, Integer k) {
source_py: def find_maximum_average_subarray_of_k_length_1(arr, n, k):
      if (k > n):
          return (- 1)
      sum = arr[0]
      for i in range(1, k):
          sum += arr[i]
      max_sum = sum
      max_end = (k - 1)
      for i in range(k, n):
          sum = ((sum + arr[i]) - arr[(i - k)])
          if (sum > max_sum):
              max_sum = sum
              max_end = i
      return ((max_end - k) + 1)
source_cpp: int find_maximum_average_subarray_of_k_length_1(vector<int> arr, int n, int k) {
    if ( k > n ) return - 1;
    int sum = arr [ 0 ];
    for ( int i = 1;
    i < k;
    i ++ ) sum += arr [ i ];
    int max_sum = sum, max_end = k - 1;
    for ( int i = k;
    i < n;
    i ++ ) {
      int sum = sum + arr [ i ] - arr [ i - k ];
      if ( sum > max_sum ) {
        max_sum = sum;
        max_end = i;
      }
    }
    return max_end - k + 1;
  }
question_info.extension: java
question_info.entry_fn_name: findMaximumAverageSubarrayOfKLength1
question_info.entry_cls_name: Solution
question_info.test_list: [{"idx": 0, "outputs": 1, "inputs": {"arr": [2, 5, 11, 37, 41, 49, 49, 63, 98], "n": 8, "k": 7}}, {"idx": 1, "outputs": -1, "inputs": {"arr": [84, -72, 12, 0, 86, -32, -18, 48, 60, 42, 8, -6, -10, -6, -52, -84, -98, 76, -10, -14, -94, -48, 94, -10, -20, 40, -52, 0, 94, -68, 44, -34, -26, -6, -94, 34, -80, -62, -40, 56, 52, -20, 74, -46, -88, -26, 22], "n": 34, "k": 43}}, {"idx": 2, "outputs": -1, "inputs": {"arr": [0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], "n": 11, "k": 18}}, {"idx": 3, "outputs": 0, "inputs": {"arr": [94, 97, 74, 88, 14, 66, 65, 50, 76, 55, 70, 93, 53, 30, 2, 60, 65, 24, 80, 73, 84, 95, 49, 32, 55, 70, 17, 26, 96, 20, 36, 2, 89, 49, 83, 67, 42, 51, 71, 11, 61, 78, 17, 78, 94, 68], "n": 35, "k": 33}}, {"idx": 4, "outputs": -1, "inputs": {"arr": [-98, -90, -60, -38, 38, 42], "n": 3, "k": 5}}, {"idx": 5, "outputs": -1, "inputs": {"arr": [1, 0, 0, 1, 1, 1, 1], "n": 3, "k": 4}}, {"idx": 6, "outputs": -1, "inputs": {"arr": [4, 9, 17, 17, 19, 32, 35, 36, 37, 40, 44, 45, 47, 48, 48, 56, 56, 60, 61, 65, 66, 79, 83, 91, 93, 99], "n": 22, "k": 24}}, {"idx": 7, "outputs": -1, "inputs": {"arr": [78, 82, -92, -46, -16, -64, 28, 60, 64, 52, 54, -84, 70, 22, 24, 0, -14, 20, -90, 30, 0, 86, 12, 72, -64, -52, 86, 16, -42], "n": 25, "k": 27}}, {"idx": 8, "outputs": 5, "inputs": {"arr": [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1], "n": 25, "k": 20}}, {"idx": 9, "outputs": 4, "inputs": {"arr": [81, 77, 6, 3, 72, 24, 75, 47, 17, 29, 69, 15, 15, 50, 30, 83, 11, 7, 59, 7, 12, 82, 45, 76, 9, 48, 98, 49, 29, 66, 3, 53, 37, 13, 72, 58, 37, 87, 55], "n": 34, "k": 23}}]
question_info.test_code: import static java.util.Map.entry;  
  import java.util.*;
  import java.lang.*;
  // TESTING CODE 
  // ============================================
  class QuestionEvaluator {
      public static String validateSolution(ArrayList<Integer> arr, Integer n, Integer k, Integer expected){
          try{
              Driver driver = new Driver();
              if (driver.run(arr, n, k,expected)){
                  return "PASSED";
              }
              return "FAILED";
              
          } catch (Exception exception_obj){
              return exception_obj.getClass().getSimpleName();
          }
  
      }
      public static void main(String[] args) {
          String result;
          result = validateSolution(new ArrayList<>(Arrays.asList(2, 5, 11, 37, 41, 49, 49, 63, 98)), 8, 7, 1);
          System.out.println(String.format("%s%s","TEST-0...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(84, -72, 12, 0, 86, -32, -18, 48, 60, 42, 8, -6, -10, -6, -52, -84, -98, 76, -10, -14, -94, -48, 94, -10, -20, 40, -52, 0, 94, -68, 44, -34, -26, -6, -94, 34, -80, -62, -40, 56, 52, -20, 74, -46, -88, -26, 22)), 34, 43, -1);
          System.out.println(String.format("%s%s","TEST-1...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)), 11, 18, -1);
          System.out.println(String.format("%s%s","TEST-2...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(94, 97, 74, 88, 14, 66, 65, 50, 76, 55, 70, 93, 53, 30, 2, 60, 65, 24, 80, 73, 84, 95, 49, 32, 55, 70, 17, 26, 96, 20, 36, 2, 89, 49, 83, 67, 42, 51, 71, 11, 61, 78, 17, 78, 94, 68)), 35, 33, 0);
          System.out.println(String.format("%s%s","TEST-3...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(-98, -90, -60, -38, 38, 42)), 3, 5, -1);
          System.out.println(String.format("%s%s","TEST-4...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(1, 0, 0, 1, 1, 1, 1)), 3, 4, -1);
          System.out.println(String.format("%s%s","TEST-5...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(4, 9, 17, 17, 19, 32, 35, 36, 37, 40, 44, 45, 47, 48, 48, 56, 56, 60, 61, 65, 66, 79, 83, 91, 93, 99)), 22, 24, -1);
          System.out.println(String.format("%s%s","TEST-6...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(78, 82, -92, -46, -16, -64, 28, 60, 64, 52, 54, -84, 70, 22, 24, 0, -14, 20, -90, 30, 0, 86, 12, 72, -64, -52, 86, 16, -42)), 25, 27, -1);
          System.out.println(String.format("%s%s","TEST-7...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1)), 25, 20, 5);
          System.out.println(String.format("%s%s","TEST-8...",result));    
      
          result = validateSolution(new ArrayList<>(Arrays.asList(81, 77, 6, 3, 72, 24, 75, 47, 17, 29, 69, 15, 15, 50, 30, 83, 11, 7, 59, 7, 12, 82, 45, 76, 9, 48, 98, 49, 29, 66, 3, 53, 37, 13, 72, 58, 37, 87, 55)), 34, 23, 4);
          System.out.println(String.format("%s%s","TEST-9...",result));    
      
      }
  }
  
  class Driver{
      public boolean run(ArrayList<Integer> arr, Integer n, Integer k, Integer expected){
  
          PLACEHOLDER_CLS_NAME sol = new PLACEHOLDER_CLS_NAME();
          return validateSolution(sol.PLACEHOLDER_FN_NAME(arr, n, k),expected);
      }
      
      public boolean validateSolution(Integer actual, Integer expected){
          return actual.equals(expected);
      }
  }
  
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
question_info.test_case_ids: 0 1 2 3 4 5 6 7 8 9
question_info.commands: java __FILENAME__