Real-Time Temperature Window Statistics
Reported by candidates from Google's online assessment. Pattern, common pitfall, and the honest play if you blank under the timer.
Google flagged this one in September 2026, and the detail that matters is the output format: averages come back as reduced fractions like "13/3", not decimals. It's a streaming window problem with ADD, AVERAGE and MAX operations, and a fixed windowSize. If you've got an OA invite, expect to maintain a rolling sum and a sliding window maximum at once. Nothing exotic, but the edge cases are where people lose points. StealthCoder sits invisibly on your screen as a safety net if you blank mid-assessment, but the pattern below should get you through on your own.
The problem
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. Return one string per AVERAGE or MAX operation, in query order. ADD operations produce no output. Function temperatureWindowStatistics(operations: String[], windowSize: int) → String[] Examples Example 1 operations = ["AVERAGE","MAX","ADD 5","AVERAGE","MAX","ADD 1","ADD 9","AVERAGE","MAX","ADD 3","AVERAGE","MAX"] windowSize = 3 return = ["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]. Example 2 operations = ["ADD -4","ADD 2","AVERAGE","MAX","ADD -2","AVERAGE","MAX"] windowSize = 2 return = ["-1/1","2","0/1","2"] The first window [-4,2] has average -1/1 and maximum 2. After adding -2, the active window is [2,-2], whose average is 0/1. Constraints 1 <= operations.length <= 100000. 1 <= windowSize <= 100000. Every operation is exactly ADD <temperature>, AVERAGE, or MAX. -1000000000 <= temperature <= 1000000000. Use signed 64-bit arithmetic for the rolling sum.
Reported by candidates. Source: FastPrep
Pattern and pitfall
The trick is two structures running side by side. Keep a queue of readings plus a running sum in 64-bit, subtracting the evicted value when the queue exceeds windowSize. For MAX, use a monotonic deque that holds decreasing values. On each ADD, pop smaller values off the back, push the new one, and pop the front if it's the element being evicted. Both queries are then O(1). The pitfalls are in formatting. Reduce the fraction with gcd of the absolute sum and the count, keep the denominator positive, and print zero as 0/1. A negative sum like -1/1 keeps its sign on the numerator. Return "null" for any query before the first ADD. Don't rescan the window per query, since 100000 operations will time out. If the deque logic slips under pressure, StealthCoder is the hedge during the live OA.
Memorize the pattern. If you can't, run StealthCoder. The proctor sees the IDE. They don't see what's behind it.
You can drill Real-Time Temperature Window Statistics cold, or you can hedge it. StealthCoder runs invisibly during screen share and surfaces a working solution in under 2 seconds. The proctor sees the IDE. They don't see what's behind it. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge.
Get StealthCoderRelated leaked OAs
You've seen the question.
Make sure you actually pass Google's OA.
Google reuses patterns across OAs. Made by an engineer who treats the OA as theater. If yours is tonight, you don't have time to grind. You have time to hedge. Works on HackerRank, CodeSignal, CoderPad, and Karat.
Real-Time Temperature Window Statistics FAQ
What's the trick in Google's Real-Time Temperature Window Statistics?+
Pair a running sum with a monotonic deque. The sum gives the average in O(1) after subtracting evicted readings. The deque keeps window maximum candidates in decreasing order, so MAX reads the front. Both update in amortized O(1) per ADD.
How do I format the average correctly?+
Compute the gcd of the absolute value of the sum and the window count, divide both, and keep the denominator positive. The sign lives on the numerator. If the sum is zero, output 0/1. Don't use floating point at all.
What happens when AVERAGE or MAX comes before any ADD?+
Return the string "null" for that query. Once at least one reading exists, the window is whatever has been added so far, up to windowSize readings. Example 1 shows two null outputs before ADD 5.
Do I need 64-bit integers for the sum?+
Yes. Temperatures reach 1,000,000,000 in magnitude and windows hold up to 100000 readings, so the sum can reach 10^14. That overflows 32-bit ints. Use long in Java or C++, and Python handles it natively.
How do I prepare for this in 48 hours?+
Write the sliding window maximum with a deque once from scratch, then add the rolling sum and the fraction reducer. Test with negatives, windowSize 1, and queries before any ADD. That covers nearly every failure case in this problem.