g | x | w | all
Bytes Lang Time Link
102Rust250608T182715Zcorvus_1
077Haskell250601T220705ZIbozz91
nanGo250531T025659ZAhamad
024Uiua 0.17.0dev.1250531T205000Zchunes
033APL+WIN250530T093806ZGraham
062Ruby250530T055404ZG B
024APLDyalog Unicode250531T110344ZMat_rdv
085JavaScript ES6250530T143023ZArnauld
123Google Sheets250530T044906Zz..
007Jelly250530T192050ZJonathan
077Maple250530T191944Zdharr
025Charcoal250530T160113ZNeil
085Desmos250530T120551ZAiden Ch
011Vyxal 3 l250530T084826Zlyxal
01005AB1E250530T081823ZKevin Cr
068Python 2250530T073349Ztata

Rust, 102 bytes

|a,k|(k..=a.len()).flat_map(|l|a.windows(l).map(move|x|x.iter().sum::<i64>().div_floor(l
as _))).max()

Playground

Haskell, 98 96 77 bytes

k!a=maximum[(`div`x).sum.take x.drop y$a|x<-[k..length a],y<-[0..length a-x]]

Try it Online!

This is my first time golfing, so there might be more to save.

Edit: Saved more by using the list monad

Go, 213 188 178 bytes

Saved (25+10=35) bytes thanks to @ceilingcat

Golfed version. Attempt This Online!

import"slices"
func f(l[]int,k int)int{if len(l)<k{return 0}
s:=[]int{}
for i:=range-^len(l)-k{t:=0
for j:=range k{t+=l[i+j]}
s=append(s,t)}
return max(slices.Max(s)/k,f(l,k+1))}

Ungolfed version. Attempt This Online!

package main

import "fmt"

// This function calculates the maximum average of consecutive elements in an array using integer division
func f(list []int, windowSize int) int {
	// Base case: if the window size is larger than the list, return 0
	if len(list) < windowSize {
		return 0
	}

	// Calculate the sum of each consecutive window of elements
	var sumsOfWindows []int
	for i := 0; i <= len(list)-windowSize; i++ {
		sum := 0
		for j := 0; j < windowSize; j++ {
			sum += list[i+j]
		}
		sumsOfWindows = append(sumsOfWindows, sum)
	}

	// Find the maximum sum and calculate the average (integer division)
	maxSum := max(sumsOfWindows)
	currentMaxAverage := maxSum / windowSize

	// Recursively find the max average with a larger window size
	nextWindowMaxAverage := f(list, windowSize+1)

	// Return the larger of the two averages
	if currentMaxAverage > nextWindowMaxAverage {
		return currentMaxAverage
	}
	return nextWindowMaxAverage
}

// Helper function to find maximum in a slice of integers
func max(slice []int) int {
	if len(slice) == 0 {
		return 0
	}
	maxVal := slice[0]
	for _, v := range slice {
		if v > maxVal {
			maxVal = v
		}
	}
	return maxVal
}

func main() {
	fmt.Println(f([]int{7, 1, 6, 2, 8}, 2)) // Should output 7
	fmt.Println(f([]int{7, 1, 7}, 2))       // Should output 4
}

Uiua 0.17.0-dev.1, 24 bytes SBCS

⌊/↥/◇⊂⍚⌟⧈(÷⊃⧻/+)⊂⊸⍜-⇡⊙⊸⧻

Try on Uiua Pad!

Explanation

                        ⊙⊸⧻  # place length of arr beneath k
                  ⊂⊸⍜-⇡      # inclusive range from k to len(arr)
       ⍚⌟                     # map over range, fixing input arr and boxing output
         ⧈(÷⊃⧻/+)            # windows by mean
   /◇⊂                        # concat boxed arrays
 /↥                           # maximum
⌊                             # floor

APL+WIN, 33 bytes

Prompts for k followed by vector of integers.

⌈/⌊(∊⌈/¨k+/¨⊂n)÷k←k+0,⍳(⍴n←⎕)-k←⎕

Try it online! Thanks to Dyalog Classic

Explanation

k←⎕       Prompt for k and assign to the variable
n←⎕       Prompt for n and assign to variable
⍴n        Length of n
k←k+0,⍳    k becomes a vector of lengths k to ⍴n
k+/¨⊂n    Sum successive elements of n by lengths k
∊⌈/¨      Find the maximum of each sum
(...)÷k   Divide each sum by its length
⌈/⌊       Round down the resulting averages and find the maximum

Ruby, 62 bytes

->l,k{(k..l.size).map{|n|l.each_cons(n).map(&:sum).max/n}.max}

Attempt This Online!

Thanks Value Ink for the fixes and for -2 bytes on the final version.

APL(Dyalog Unicode), 24 bytes SBCS

{⌈/∊(⍺↓0,⍳≢⍵)(⌊+/÷⊣)¨⊂⍵}

Try it on APLgolf!

K is the left argument and an array is the right.

Explanation

                      ⍵      the right argument (an array)
                     ⊂       Enclose (to treat the entire array as one scalar)
                    ¨        Each
             (     )         tacit function: X (e f g h) Y ←→ e (X f Y) g (X h Y)
                  ⊣          Left argument
                 ÷           Divide
                /            (n-wise) Reduction
               +        
               +/            n-wise sum
              ⌊              Round down
             (⌊+/÷⊣)        rounded down rolling average
    (       )           
           ⍵            
          ≢                 Tally (length)
         ⍳                   Index Generator (numbers from 1 to a right argument)
        ,                   Concatenate
       0                
      ↓                     Drop
     ⍺                      the left argument (K)
    (⍺↓0,⍳≢⍵)               numbers from K to the length of array
    (⍺↓0,⍳≢⍵)(⌊+/÷⊣)¨⊂⍵    averages of all contiguous subarrays of length at least K, combined by the length
   ∊                        Enlist (list all values in one vector)
  /                         Reduce
 ⌈                          Maximum
{⌈/∊(⍺↓0,⍳≢⍵)(⌊+/÷⊣)¨⊂⍵}  solution

JavaScript (ES6), 85 bytes

Expects (K)(array).

k=>g=([v,...a],n=0,s=0,i)=>q=!i/v?g(a,n+1,s+v)<g(a,n,s,n,v=q)?q:v:n<k?g:s/n-(s%n<0)|0

Try it online!

Commented

k =>                // outer function taking k
g = (               // g = inner recursive function taking:
  [ v,              //   v = current value from the input array
    ...a            //   a[] = remaining values
  ],                //
  n = 0,            //   n = number of values in the subarray
  s = 0,            //   s = sum of all values in the subarray
  i                 //   i = flag set when the subarray is closed
) =>                //
q =                 // save the result of this call in q
!i / v ?            // if i is not set and v is defined:
  g(                //   1st recursive call where:
    a, n + 1, s + v //     v is included in the subarray
  )                 //
  <                 //   (compare)
  g(                //   2nd recursive call where:
    a, n, s,        //     v is not included in the subarray
    n,              //     i is set if n is not 0
    v = q           //     the result of the 1st call is saved in v
  ) ?               //   if v (1st call) is less than q (2nd call):
    q               //     return q
  :                 //   else:
    v               //     return v
:                   // else:
  n < k ?           //   if n is less than the target k:
    g               //     invalidate this result
  :                 //   else:
    s / n           //     return s / n
    - (s % n < 0)   //     -1 if this is a negative non-integer
    | 0             //     rounded toward 0 (*)

(*) This is a twisted and 2-byte shorter way of just doing Math.floor(s/n).

Google Sheets, 123 bytes

=SORT(MAX(MAP(A2:A,LAMBDA(a,MAP(SEQUENCE(1,COUNT(A2:A)-A1+1,A1),LAMBDA(i,IFERROR(INT(1/AVERAGE(N(OFFSET(a,,,i)))^-1))))))))

Expects K in A1 and the array from A2 onwards.

Jelly, 7 bytes

ẆṫƇÆmṀḞ

A dyadic Link that accepts the list of \$n\$ integers on the left and the minimal sublist length, \$k\$, on the right and yields the maximal floored mean of the sublists of at least length \$k\$.

Try it online!

How?

ẆṫƇÆmṀḞ - Link: list of integers, L; positive integer, K
Ẇ       - all non-empty, contiguous sublists of L
  Ƈ     - keep those for which:
 ṫ      -   tail from 1-index K (an empty list is falsey)
   Æm   - mean (vectorises)
     Ṁ  - maximum
      Ḟ - floor (towards -inf)

Maple, 77 bytes

(A,K)->max(seq(seq(floor(add(A[i..i+k-1])/k),i=1..n-k+1),k=K..(n:=nops(A))));

Input is list A and positive integer K.

Charcoal, 25 bytes

I⌈E…·θLη÷⌈E…·ιLηΣ✂η⁻λιλ¹ι

Try it online! Link is to verbose version of code. Explanation:

  E                         Map over
   …·                       Inclusive range from
     θ                      Input `K` to
       η                    Input array
      L                     Length
          E                 Map over
           …·               Inclusive range from
             ι              Current value to
               η            Input array
              L             Length
                  η         Input array
                 ✂    ¹     Sliced from
                    λ       Inner value
                   ⁻        Subtract
                     ι      Outer value
                      λ     To inner value
                Σ           Take the sum
         ⌈                  Take the maximum
        ÷                   Integer divided by
                        ι   Current value
 ⌈                          Take the maximum
I                           Cast to string
                            Implicitly print

Desmos, 85 bytes

l=L.count
a=floor(L.total/l)
f(L,k)=\{l>k:[f(L[2...],k),f(L[1...l-1],k),a],[a]\}.\max

Port of tata's Python 2 answer so make sure to upvote that as well.

Try It On Desmos!

Try It On Desmos! - Prettified

Vyxal 3 -l, 11 (literate) bytes

sublists filter< 
  length second-input >=
} 
each: arithmetic-mean max-of 
floor

Vyxal It Online!

Could be a lot shorter if it wasn't at least K :p

05AB1E, 10 bytes

ŒʒgI@}ÅAàï

Inputs in the order \$list,K\$.

Try it online or verify both test cases.

Explanation:

Œ       # Get all sublists of the first (implicit) input-list
 ʒ      # Filter it by:
  g     #  Get the length of the current sublist
   I@   #  Check that it's >= the second input-integer
 }ÅA    # After the filter: get the average of each remaining sublist
    à   # Pop and keep the maximum
     ï  # Floor it to an integer
        # (which is output implicitly as result)

Python 2, 68 bytes

f=lambda a,k:max([sum(a)/len(a)]+(a[k:]and[f(a[1:],k),f(a[:-1],k)]))

Try it online!