Compute Peak KV Cache Usage Across Overlapping Requests
Last updated: November 29, 2026
Quick Overview
Given inference requests as (start, end, tokens) where each request holds that many KV cache tokens on the half-open interval [start, end), return the peak total tokens held at once and the earliest time that peak occurs.
Anthropic
November 29, 20260
0
0 solved
Given inference requests as (start, end, tokens) where each request holds that many KV cache tokens on the half-open interval [start, end), return the peak total tokens held at once and the earliest time that peak occurs.
Serving Claude means packing many concurrent requests onto accelerators whose memory is dominated by KV cache, so capacity questions about overlapping requests come up naturally. As a phone screen warm-up, the interviewer checks a clean sweep line, the correct tie rule at shared endpoints, and whether you clarify interval semantics before coding.
What the Interviewer Expects
- Asks whether intervals are open or closed at the end before writing code
- Uses a sweep over sorted start and end events with weights
- Processes releases before acquisitions at the same timestamp for half-open intervals
- Reports the earliest time the peak is reached
- Handles empty input and zero-length requests
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
- How would you answer many queries of the form 'peak usage between times a and b'?
- Requests arrive as a live stream. How do you maintain current usage and alert when it crosses a threshold?
- If usage grows linearly over a request's life as tokens are generated, how does the computation change?
- Given a fixed memory budget, how would you find the minimum delay to impose on requests so the peak fits?
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 of (start, end, tokens) with integer times. A request occupies memory on [start, end), so a request ending at 10 and one starting at 10 do not overlap. Output: `(peak_tokens, earliest_...
High-Level Design
Turn each request into two events: +tokens at start and -tokens at end. Sort by time and apply every event at the same timestamp before checking the running total, so the check reflects the true u...