Peak Concurrent Queries Per Virtual Warehouse From Query History
Last updated: November 29, 2026
Quick Overview
Given query history rows (warehouse, start_time, end_time) with half-open intervals, return for each warehouse the maximum number of queries running at once and the earliest time that peak is reached.
Snowflake
November 29, 20260
0
0 solved
Given query history rows (warehouse, start_time, end_time) with half-open intervals, return for each warehouse the maximum number of queries running at once and the earliest time that peak is reached.
Concurrency per warehouse drives Snowflake decisions like when a multi-cluster warehouse should add a cluster, so this sweep line question appears in early technical screens. The interviewer checks event ordering at equal timestamps and clean grouping by key.
What the Interviewer Expects
- Groups events by warehouse before sweeping
- Turns each query into a +1 start event and a -1 end event
- Orders ends before starts at the same timestamp because intervals are half-open
- Tracks the first time the running count exceeds the previous peak
- States O(n log n) time
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 return the full concurrency timeline instead of just the peak?
- How do you compute peak concurrency when the history does not fit in memory?
- How would you find how many seconds a warehouse spent above a concurrency limit of 8?
- What changes if end_time can be null for still-running queries?
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 query occupies [start, end). A query ending at t and one starting at t do not overlap. Output per warehouse: (peak, first_time_peak_reached). Zero-length or malformed intervals (`end <= start...
High-Level Design
Sweep line per warehouse: emit (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-open rule. Th...