Highest Average Daily Watch Time Over Any K Consecutive Days

Last updated: November 29, 2026

Quick Overview

Given daily YouTube watch minutes for a channel and an integer k, return the highest average over any k consecutive days.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Phone Screen
Coding & Algorithms
Easy

0

0

0 solved


Given daily YouTube watch minutes for a channel and an integer k, return the highest average over any k consecutive days.

A fixed-size sliding window warm-up in the style of Google's phone screens, framed around creator analytics in YouTube Studio. The interviewer checks that the candidate updates a running sum in O(1) per step instead of re-summing each window.

What the Interviewer Expects
  • Maintains a running window sum
  • Adds the entering element and subtracts the leaving one
  • Compares sums, dividing only once at the end
  • Validates k against the array length
  • States O(n) time and O(1) space
Key Topics to Cover
Sliding Window
Fixed Window
Running Sum
Arrays
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
  • What if you need the window with the highest average among all windows of length at least k?
  • How would you return the start date of the best window as well?
  • How would you compute this over a live stream of daily values?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice DSA Problems
Sample Answer
Requirements
  • Input: list minutes of numbers, integer k with 1 <= k <= len(minutes).
  • Output: the maximum mean of any contiguous block of exactly k days, as a float.
  • Raise an error for invalid k rath...
High-Level Design

Sum the first k days. Then slide the window one day at a time: add minutes[i] and subtract minutes[i - k], which is the day that just fell out. Track the best sum seen. Because every window has ...


Submit Your Answer
Markdown supported