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.
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
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- 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 ProblemsSample Answer
Requirements
- Input: list
minutesof numbers, integerkwith1 <= k <= len(minutes). - Output: the maximum mean of any contiguous block of exactly
kdays, as a float. - Raise an error for invalid
krath...
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 ...