title: Find Maximum Average Subarray Of K Length 1
signature: function find_maximum_average_subarray_of_k_length_1(arr, n, k)
test_code: 
  
  -- SOLUTION CODE
  -- ============================================
  PLACEHOLDER_CODE_BODY
  
  -- TESTING CODE 
  -- ============================================
  function isCorrect(actual, expected)
      if type(expected) ~= type(actual) then
          return false
      end
      
      if type(expected) == 'table' then
          for k,v_expected in pairs(expected) do
              
              if actual[k] == nil then
                  return false
              end
              local v_actual = actual[k]
              if not isCorrect(v_actual, v_expected) then
                  return false
              end
              actual[k]=nil
          end
      
          if next(actual) then 
              return false
          end
          return true
      else
          return actual == expected
      end
  end
  
  function validateSolution(actual, expected)
      return isCorrect(actual,expected)
  end
  
  function driver(arr, n, k, expected)
      local exec_result;
      local status, error_msg = pcall(function () 
          exec_result=PLACEHOLDER_FN_NAME(arr, n, k) 
      end)
      if status then
          if validateSolution(exec_result,expected) then
              return "PASSED"
          end
          return "FAILED"
      else
          return string.format("ERROR=%s",string.gsub(error_msg,".*:[%d]+: ",""))
      end
  end
      
  function main()
      result = driver({2, 5, 11, 37, 41, 49, 49, 63, 98}, 8, 7, 1)
      print(string.format("TEST-0...%s",result))
  
      result = driver({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)
      print(string.format("TEST-1...%s",result))
  
      result = driver({0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1}, 11, 18, -1)
      print(string.format("TEST-2...%s",result))
  
      result = driver({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)
      print(string.format("TEST-3...%s",result))
  
      result = driver({-98, -90, -60, -38, 38, 42}, 3, 5, -1)
      print(string.format("TEST-4...%s",result))
  
      result = driver({1, 0, 0, 1, 1, 1, 1}, 3, 4, -1)
      print(string.format("TEST-5...%s",result))
  
      result = driver({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)
      print(string.format("TEST-6...%s",result))
  
      result = driver({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)
      print(string.format("TEST-7...%s",result))
  
      result = driver({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)
      print(string.format("TEST-8...%s",result))
  
      result = driver({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)
      print(string.format("TEST-9...%s",result))
  
  end
  
  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;
  }