Peak Concurrent Calls by UTC Day
Learn this problemProblem statement
You are given records for completed phone calls. Record i belongs to customer customerIds[i], has unique identifier callIds[i], and is active during the half-open interval [startTimestamps[i], endTimestamps[i]). Timestamps are Unix milliseconds in UTC.
For every customer and every UTC date on which at least one of that customer's calls is active, find the maximum number of concurrent calls during that date.
Peak selection
- Choose the earliest millisecond in the date at which the maximum concurrency is active.
- A call ending at a timestamp is not active at that timestamp. A call starting at that timestamp is active.
- Include exactly the call IDs active at the chosen timestamp, sorted lexicographically.
Return format
Return one string per customer-date pair in this exact format:
customerId|YYYY-MM-DD|maxConcurrentCalls|timestamp|callId1,callId2,...Sort the returned strings by numeric customer ID, then by date. A call spanning midnight contributes independently to each UTC date it intersects.
Function
peakConcurrentCalls(customerIds: int[], callIds: String[], startTimestamps: long[], endTimestamps: long[]) → String[]Examples
Example 1
customerIds = [1,1,1,2]callIds = ["A","B","C","X"]startTimestamps = [0,10,20,86399990]endTimestamps = [30,20,86400010,86400020]return = ["1|1970-01-01|2|10|A,B","1|1970-01-02|1|86400000|C","2|1970-01-01|1|86399990|X","2|1970-01-02|1|86400000|X"]Customer 1 first reaches two active calls at timestamp 10. Call C continues into the next UTC date. Customer 2's call also crosses midnight, so both customers have a record for 1970-01-02.
Example 2
customerIds = [7,7]callIds = ["left","right"]startTimestamps = [100,200]endTimestamps = [200,300]return = ["7|1970-01-01|1|100|left"]The first call ends exactly when the second begins, so the half-open intervals never overlap. The earliest timestamp with the maximum concurrency of 1 is 100.
Example 3
customerIds = [4,4]callIds = ["before","after"]startTimestamps = [86399999,86400000]endTimestamps = [86400000,86400001]return = ["4|1970-01-01|1|86399999|before","4|1970-01-02|1|86400000|after"]The call ending at midnight belongs only to 1970-01-01. The call starting at midnight belongs to 1970-01-02.
Constraints
1 <= customerIds.length <= 100000- All four input arrays have the same length.
1 <= customerIds[i] <= 10^9- Every
callIds[i]is unique, nonempty, and contains only ASCII letters, digits, underscores, or hyphens. 0 <= startTimestamps[i] < endTimestamps[i] <= 4102444800000- Across all calls, the total number of intersected UTC dates is at most
200000.