Maximize Batch Value by Grouping Consecutive Requests Into Small Batches
Last updated: November 29, 2026
Quick Overview
Requests in a queue must be split into consecutive batches of at most k requests; each batch is billed as its highest-priority value times its size. Return the maximum total billed value.
0
0
0 solved
Requests in a queue must be split into consecutive batches of at most k requests; each batch is billed as its highest-priority value times its size. Return the maximum total billed value.
A Google screen DP where the state is a prefix and the choice is the length of the last batch. Interviewers check the backward inner loop with a running maximum and the bound on batch length.
What the Interviewer Expects
- Define best[i] for the first i requests
- Try last batch lengths 1..k ending at i
- Maintain the running max inside the inner loop
- Give O(n k) time and O(n) space
- Trace an example by hand
Key Topics to Cover
How to Approach This
- Clarify input constraints and edge cases before writing code.
- Walk through your approach verbally and confirm with the interviewer before coding.
- Start with a brute force solution, then optimize. Mention time and space complexity.
- Test your solution with examples, including edge cases like empty input or duplicates.
- Consider common patterns: sliding window, two pointers, hash map, BFS/DFS, dynamic programming.
Possible Follow-up Questions
- Each batch also costs a fixed overhead c.
- Batches must have length exactly k except possibly the last.
- Minimize instead of maximize.
- Return the batch boundaries.
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Input: list p of integers and integer k >= 1. Split p into contiguous groups of size 1..k. Each group's value is max(group) * len(group). Output the maximum total value....
High-Level Design
Let best[i] be the maximum total for the first i requests, best[0] = 0. The last batch covers p[i-L..i-1] for some L in 1..min(k, i). As L grows, keep m = max(m, p[i-L]) so each candidate is O...