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.

Google
Coding & Algorithms
Software Engineer
Google
November 29, 2026
Software Engineer
Technical Screen
Coding & Algorithms
Medium

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
1D dynamic programming
Partition DP
Running maximum
Prefix states
How to Approach This
  1. Clarify input constraints and edge cases before writing code.
  2. Walk through your approach verbally and confirm with the interviewer before coding.
  3. Start with a brute force solution, then optimize. Mention time and space complexity.
  4. Test your solution with examples, including edge cases like empty input or duplicates.
  5. 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 Problems
Sample 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...


Submit Your Answer
Markdown supported