title: Find Maximum Average Subarray Of K Length 1
signature: find_maximum_average_subarray_of_k_length_1 <- function(arr, n, k) {
test_code: 
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  validate_solution <- function(actual, expected) {
      toString(actual)==toString(expected)
  }
  
  driver <- function(arr, n, k, expected){
      if (validate_solution(PLACEHOLDER_FN_NAME(arr, n, k), expected)){
          "PASSED"
      } else{
          "FAILED"
      }
  }
  
  main <- function() {
      cat(sprintf("TEST-0...%s\n",driver(
          list(2L, 5L, 11L, 37L, 41L, 49L, 49L, 63L, 98L), 8L, 7L, 
          1L
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          list(84L, -72L, 12L, 0L, 86L, -32L, -18L, 48L, 60L, 42L, 8L, -6L, -10L, -6L, -52L, -84L, -98L, 76L, -10L, -14L, -94L, -48L, 94L, -10L, -20L, 40L, -52L, 0L, 94L, -68L, 44L, -34L, -26L, -6L, -94L, 34L, -80L, -62L, -40L, 56L, 52L, -20L, 74L, -46L, -88L, -26L, 22L), 34L, 43L, 
          -1L
      )))
  
      cat(sprintf("TEST-2...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 11L, 18L, 
          -1L
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          list(94L, 97L, 74L, 88L, 14L, 66L, 65L, 50L, 76L, 55L, 70L, 93L, 53L, 30L, 2L, 60L, 65L, 24L, 80L, 73L, 84L, 95L, 49L, 32L, 55L, 70L, 17L, 26L, 96L, 20L, 36L, 2L, 89L, 49L, 83L, 67L, 42L, 51L, 71L, 11L, 61L, 78L, 17L, 78L, 94L, 68L), 35L, 33L, 
          0L
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          list(-98L, -90L, -60L, -38L, 38L, 42L), 3L, 5L, 
          -1L
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          list(1L, 0L, 0L, 1L, 1L, 1L, 1L), 3L, 4L, 
          -1L
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          list(4L, 9L, 17L, 17L, 19L, 32L, 35L, 36L, 37L, 40L, 44L, 45L, 47L, 48L, 48L, 56L, 56L, 60L, 61L, 65L, 66L, 79L, 83L, 91L, 93L, 99L), 22L, 24L, 
          -1L
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          list(78L, 82L, -92L, -46L, -16L, -64L, 28L, 60L, 64L, 52L, 54L, -84L, 70L, 22L, 24L, 0L, -14L, 20L, -90L, 30L, 0L, 86L, 12L, 72L, -64L, -52L, 86L, 16L, -42L), 25L, 27L, 
          -1L
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          list(0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 0L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L), 25L, 20L, 
          5L
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          list(81L, 77L, 6L, 3L, 72L, 24L, 75L, 47L, 17L, 29L, 69L, 15L, 15L, 50L, 30L, 83L, 11L, 7L, 59L, 7L, 12L, 82L, 45L, 76L, 9L, 48L, 98L, 49L, 29L, 66L, 3L, 53L, 37L, 13L, 72L, 58L, 37L, 87L, 55L), 34L, 23L, 
          4L
      )))
  
  }
  
  main()
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;
  }