Question bank › Sliding Window
Dsa Sliding Window Easy

Premium Batch Shipping

A logistics company ships items in batches of a fixed size W. Each item has a shipping cost. A batch is considered 'Premium' if it contains no more than E items with a cost strictly greater than threshold T. Find the maximum total cost of any valid Premium batch. Input Format: - The first line contains four integers: W (batch size), E (max premium items), T (cost threshold), and N (total items). - The second line contains N space-separated integers representing the costs of the items in order. Output Format: - Print the maximum sum of a valid batch. If no batch is valid, print -1. Example: Input: 3 1 10 5 5 12 15 7 8 Output: 30 Explanation: Window [15, 7, 8] has sum 30 and only one item (15) > 10. Window [5, 12, 15] is invalid because it has two items > 10.

Key concepts

sliding_windowfixed_windowoptimization

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.