A public charging hub logs n charging sessions. Session i runs over the half-open interval [start, end) (a session that ends at time x is no longer active at time x). Find the greatest number of sessions that are active at the same instant.
Line 1: an integer n.
Next n lines: two integers start end (with start < end).
A single integer: the maximum number of simultaneously active sessions.
Example 1
Input
3 0 3 1 4 2 5
Expected
3
Explanation
At instant 2 all three windows [0,3), [1,4), [2,5) are active, so the peak overlap is 3.
Example 2
Input
3 0 1 1 2 2 3
Expected
1
Explanation
Each window ends exactly where the next begins, so no two are active at once: 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 →