A single attendee has n seminars on their wish list. Seminar i runs during the half-open interval [s, e) with s < e. The attendee can go to every seminar only if no two of them overlap in time; a seminar that ends exactly when another begins does NOT overlap it (touching at an endpoint is fine).
Decide whether all n seminars can be attended.
Line 1: an integer n.
Next n lines: two integers s and e describing one seminar's half-open interval [s, e).
Print YES if all seminars can be attended (no two overlap), otherwise print NO.
Example 1
Input
3 0 2 2 4 5 6
Expected
YES
Explanation
Sorted: [0,2), [2,4), [5,6). Each starts at or after the previous one ends, so nothing overlaps: YES.
Example 2
Input
2 0 5 3 8
Expected
NO
Explanation
[0,5) and [3,8) share the times in [3,5), so they overlap: NO.
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 →