Count Hotspot Playback Windows
Updated
Problem statement
You are given an integer array views, where views[i] is the number of new video playbacks recorded during minute i, and an integer threshold.
Count the nonempty ranges of consecutive minutes whose total playback count is strictly greater than threshold. Return that count.
Playback counts are nonnegative. Return the exact number of qualifying windows as a long value.
Interview extensions
- Explain how prefix sums answer many inclusive interval-total queries
[left, right]over the same playback array. - If playback corrections may be negative, explain why the monotone sliding-window argument no longer works and how to count qualifying windows in
O(n log n)time. - Discuss how to serve a very large volume of online interval queries.
- For nonnegative playback counts, explain how to process the values as a stream without storing the entire array.
Function
countHotspotWindows(views: int[], threshold: long) → longExamples
Example 1
views = [2,1,3]threshold = 3return = 2The qualifying windows are [1,3] with total 4 and [2,1,3] with total 6. Windows totaling exactly 3 do not qualify.
Example 2
views = [0,0]threshold = -1return = 3All three nonempty windows have total 0, which is strictly greater than -1.
Example 3
views = [5,0,1]threshold = 4return = 3The three qualifying windows are [5], [5,0], and [5,0,1].
Example 4
views = []threshold = 10return = 0An empty playback history contains no nonempty time window.
Constraints
0 <= views.length <= 2000000 <= views[i] <= 10^9-10^18 <= threshold <= 10^18- The answer fits in a signed 64-bit integer.
More Google Onsite Interview questions
- Route Pattern MatcherPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Evaluate a Nested Math ExpressionPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- Distinct Subset SumsONSITE INTERVIEW · Seen Nov 2026
- Playlist With No Same Artist in a RowONSITE INTERVIEW · Seen Nov 2026
- Delete Nodes and Return Forest RootsONSITE INTERVIEW · Seen Nov 2026
- Dice-Walk Winning ProbabilityPHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- First and Last Target Position in a Mountain ArrayONSITE INTERVIEW · Seen Nov 2026
- Lowest Common Ancestor in an N-ary TreePHONE SCREEN · ONSITE INTERVIEW · Seen Nov 2026
- 0/1 Knapsack with Weight and Volume LimitsONSITE INTERVIEW · Seen Nov 2026
- Batched Subsequence Word MatchesONSITE INTERVIEW · Seen Nov 2026
Similar questions at other companies
- Subarray with a Given SumExpedia · ONSITE INTERVIEWExpedia interview questions
- Shortest Window with Required CountsOracle · ONSITE INTERVIEWOracle interview questions
- Longest Binary Window with at Most K OnesLinkedIn · ONSITE INTERVIEWLinkedIn interview questions
- Trim a Telemetry Buffer to a Target SumAmazon · ONSITE INTERVIEW
- Trapping Rain WaterInMobi · ONSITE INTERVIEWInMobi interview questions
- Count Subarrays With Product Equal to KSalesforce · OASalesforce interview questions
- Subarray Product Less Than KApple · PHONE SCREENApple interview questions
- Subarray Product Less Than KAngel One · PHONE SCREEN
- Subarray Product Less Than KThe D.E. Shaw Group · PHONE SCREENThe D.E. Shaw Group interview questions
- Trapping Rain WaterGoldman Sachs · PHONE SCREENGoldman Sachs interview questions