A call center logs n calls, each a half-open interval from its start second up to (but not including) its end second. A call is active at an instant if the instant lies inside its interval. Because the intervals are half-open, a call that ends exactly when another begins are never active at the same instant. Report the maximum number of calls that are active simultaneously at any single instant.
Line 1: an integer n.
Next n lines: two integers start and end describing one call.
A single integer: the peak number of simultaneously active calls.
Example 1
Input
3 1 5 2 6 4 8
Expected
3
Explanation
At instant 4 all three calls [1,5), [2,6), [4,8) are active, so the peak is 3.
Example 2
Input
2 1 3 3 5
Expected
1
Explanation
The first call ends exactly when the second begins; with half-open intervals they never overlap, so the peak is 1.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →