Question bank › Intervals
Dsa Intervals Easy

The Focus Window

You have N tasks, each with a range $[S_i, E_i]$. You want to set a 'focus window' of fixed duration W. A task is 'contained' if its entire duration $[S_i, E_i]$ falls within the focus window $[T, T+W]$ for some start time T. Find the maximum number of tasks you can contain in a single window of duration W. Input Format: - Two integers: W (window size) and N (number of tasks). - N lines, each containing S and E. Output Format: - A single integer representing the maximum tasks contained. Example: Input: 10 3 5 12 15 22 8 18 Output: 2 Explanation: For W=10, a window from T=8 to T=18 contains [8, 18]. A window from T=5 to T=15 contains [5, 12]. A window from T=12 to T=22 contains [15, 22]. No window contains all three because the span from the start of the earliest to the end of the latest is too large.

Key concepts

sliding-windowintervalssweep-line

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.