Dsa
Prefix Sum
Medium
Thermal Equilibrium Window
You are monitoring a chemical reactor's temperature sensor. Given a sequence of N temperature readings and a target equilibrium temperature T, find the length of the longest contiguous period where the average temperature was exactly T. If no such period exists, output 0.
Input Format:
The first line contains two integers: N (the number of readings) and T (the target average).
The second line contains N space-separated integers representing the temperature readings.
Output Format:
A single integer representing the maximum length of a subarray whose mean is T.
Example:
Input:
5 3
2 4 3 3 3
Output:
5
Explanation: The average of [2, 4, 3, 3, 3] is 15/5 = 3. The entire array works.
Key concepts
prefix_sumhash_maparithmetic
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now