Peak Concurrent API Calls per Org Under a Limit
Last updated: November 29, 2026
Quick Overview
Given API call logs as (org_id, start, end) half-open intervals, return each org's peak number of simultaneous calls and the earliest time that peak is reached, then list orgs whose peak exceeds a concurrency limit.
Salesforce
November 29, 20260
0
0 solved
Given API call logs as (org_id, start, end) half-open intervals, return each org's peak number of simultaneous calls and the earliest time that peak is reached, then list orgs whose peak exceeds a concurrency limit.
Salesforce is a multi-tenant platform where governor limits, such as caps on concurrent long-running requests, protect every org on shared infrastructure. This sweep-line question checks whether you can group by tenant, handle endpoint ties correctly, and explain why the boundary rule matters for enforcement.
What the Interviewer Expects
- Clarify that intervals are half-open so a call ending at t frees capacity for one starting at t
- Build start and end events per org and sort them
- Order ends before starts at the same timestamp
- Track running count and first time of maximum
- Give O(n log n) complexity and discuss per-org grouping
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
- Calls arrive as a live stream in start order. How do you enforce the limit online?
- How would you return the full time window during which the peak held, not just its start?
- If logs come from many app servers with clock skew, how does that change your answer?
- How would you find the top 10 orgs by peak across billions of calls?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice DSA ProblemsSample Answer
Requirements
Each call is [start, end). For each org return (peak, first_time_of_peak). Separately, given limit, return sorted org IDs with peak > limit. Zero-length calls (start == end) never overlap an...
High-Level Design
A sweep line per org: turn each call into (start, +1) and (end, -1), sort, and walk while keeping a running count. Sorting tuples puts -1 before +1 at equal times, which is exactly the half-op...