Harpreet's Newsletter

Harpreet's Newsletter

Maximum Average Subarray I

Google Interview Question

Harpreet Singh's avatar
Harpreet Singh
Oct 17, 2025
∙ Paid

Problem Overview

Difficulty: Easy
LeetCode Pattern: Sliding Window

Given an array nums, find a contiguous subarray of length k that has the maximum average, and return that average value.

Note: Answer within 10-5 accuracy is acceptable.

Input: 
· nums = [1,12,-5,-6,50,3]
· k = 4

Output: 
· 12.75

Reason: 
· Subarray: [12,-5,-6,50]
· It has max average of 12…

Keep reading with a 7-day free trial

Subscribe to Harpreet's Newsletter to keep reading this post and get 7 days of free access to the full post archives.

Already a paid subscriber? Sign in
© 2025 Harpreet Singh · Privacy ∙ Terms ∙ Collection notice
Start your SubstackGet the app
Substack is the home for great culture