Dsa
Sliding Window
Easy
The Smart Irrigation
A farmer tracks daily rainfall in mm. They want to find the longest continuous period of days such that: 1) The total rainfall during the period does not exceed W mm, and 2) The number of 'Dry Days' (days with exactly 0 mm rainfall) is exactly D. If no such period exists, output 0.
Example:
Input:
7 10 2
3 0 4 0 2 5 0
Output:
5
Explanation: W=10, D=2. The period [3, 0, 4, 0, 2] has sum 9 and exactly two 0s. Length 5.
Key concepts
sliding_windowcounting
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