Question bank › Sliding Window
Dsa Sliding Window Hard

Max Length Subarray with Average Below Target

Given an array of integers `arr` and a target integer `target`, find the length of the longest contiguous subarray whose average is strictly less than `target`. If no such subarray exists, return -1. Input Format: The first line contains an integer, `n`, representing the length of the array. The second line contains `n` integers separated by spaces. The third line contains the target integer. Output Format: Output a single integer representing the length of the longest subarray where the average is below the target. Example: Input: 5 1 2 3 4 5 4 Output: 3

Key concepts

sliding_windowarrayprefix_sum

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.