Question bank › Prefix Sum
Dsa Prefix Sum Warm-up

Quiet Library Monitor

A library monitor records the noise level (in decibels) every minute for N minutes. A 'noise violation' is flagged if the average noise level from the start of the recording up to the current minute is strictly greater than a threshold T. Calculate the total number of noise violations that occurred during the N-minute period. Input Format: The first line contains two integers: N (minutes) and T (decibel threshold). The second line contains N integers representing noise levels recorded each minute. Output Format: A single integer representing the total number of violations. Example: Input: 4 50 60 40 70 30 Output: 2 (Explanation: Min 1: Avg 60/1=60 (>50, Yes). Min 2: Avg 100/2=50 (>50, No). Min 3: Avg 170/3=56.6 (>50, Yes). Min 4: Avg 200/4=50 (>50, No).)

Key concepts

prefix_sumaverages

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
Part of InterviewLab's verified interview question bank. We show the prompt and concepts to practise with — never a copy-paste solution.