FastPrepReal-Time Temperature Window Statistics
Problem · Queue

Real-Time Temperature Window Statistics

MediumGoogle logoGoogleFULLTIMEONSITE INTERVIEW
See Google hiring insights

Problem statement

Process a finite sequence of operations for a real-time temperature stream with a fixed positive windowSize. Each operation is one of:

  • ADD <temperature>: append one integer reading.
  • AVERAGE: report the exact average of the latest windowSize readings, or all readings so far when fewer exist.
  • MAX: report the maximum over that same current window.

If a query occurs before any reading has been added, return "null". Otherwise, return an average as a reduced numerator/denominator string with a positive denominator, and return a maximum as its decimal integer string. Normalize a zero average to 0/1.

The problem statement continues
Pro

Examples

Example 1

operations = ["AVERAGE","MAX","ADD 5","AVERAGE","MAX","ADD 1","ADD 9","AVERAGE","MAX","ADD 3","AVERAGE","MAX"]windowSize = 3return = ["null","null","5/1","5","5/1","9","13/3","9"]

The first two queries have no readings. After adding 5, both statistics use [5]. After 5, 1, 9, the average is 5/1 and the maximum is 9. Adding 3 evicts 5, leaving [1,9,3].

FastPrep Pro
Reported in 1 Google interview this week

Unlock this recently reported problem

FastPrep Pro gives you full access to interview problems reported within the last week.

  • Full problem statement and constraints
  • 1 more worked example, explained
  • Guided hints and editorial
  • Run your code on real test cases
$8.25/month

$99 billed yearly — or $19 month-to-month. Cancel anytime.

Free plan — 2 of 2 free unlocks used this week
CodePython 3
Run and Submit unlock with Pro
FastPrep Pro
Reported in 1 Google interview this week

Unlock this recently reported problem

FastPrep Pro gives you full access to interview problems reported within the last week.

  • Full problem statement and constraints
  • 1 more worked example, explained
  • Guided hints and editorial
  • Run your code on real test cases
$8.25/month

$99 billed yearly — or $19 month-to-month. Cancel anytime.

Free plan — 2 of 2 free unlocks used this week