Maximum Average Subarray I (Leetcode 643)
Problem Link: https://leetcode.com/problems/maximum-average-subarray-i/
class Solution:
def findMaxAverage(self, nums: List[int], k: int) -> float:
n=len(nums)
i=0
j=0
avg=float('-inf')
summ=0
while(j<n):
summ+=nums[j]
if(j-i+1<k):
j+=1
elif(j-i+1==k):
avg=max(avg,summ/k)
summ-=nums[i]
i+=1
j+=1
return avg
PreviousFind the K-Beauty of a Number (Leetcode 2269)NextNumber of Sub-arrays of Size K and Average Greater than or Equal to Threshold (Leetcode 1343)
Last updated