Dsa
Sliding Window
Easy
The Busy Barista
A barista is managing a queue of drink orders. Each drink has a preparation time in seconds. A 'complex' drink is defined as any drink taking more than M seconds to prepare. The barista wants to find the longest continuous sequence of orders they can process such that: 1) The total preparation time does not exceed T seconds, and 2) There are at most K complex drinks in the sequence. Output the length of this longest sequence.
Example:
Input:
5 10 1 4
3 5 2 1 6
Output:
3
Explanation: M=4. Drinks [3, 5, 2] have sum 10 and one complex drink (5 > 4). [5, 2, 1] also works. [3, 5, 2, 1] sums to 11, exceeding T=10.
Key concepts
sliding_windowcounters
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