Dsa
Union Find
Medium
Event Scheduling Conflict
You are managing a series of events with specific time slots. Each event either establishes a conflict relation with another event or checks if two events are in conflict. Implement a program that processes a list of actions. Each action is either 'C x y' for a check between events x and y, or 'E x y' for declaring that events x and y cannot happen at the same time. Your program should output 'YES' for each 'C x y' action if they are in conflict, otherwise output 'NO'.
Input format:
- The first line contains an integer n (1 ≤ n ≤ 10^5), the number of actions.
- The next n lines each contain a string followed by two integers. The first string is either 'E' or 'C', where integers represent events (1 ≤ x, y ≤ 10^6).
Output format:
- For each 'C x y' action, output 'YES' or 'NO' in a new line.
Example:
Input:
5
E 1 2
E 2 3
C 1 3
C 1 4
E 4 5
C 1 5
Output:
YES
NO
YES
Key concepts
union_findintervals
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now