A productivity app lets each user start a timed focus session, recorded as a closed time interval, and separately logs a timestamp every time a distracting notification reaches that user -- whether or not a focus session happens to be running. A focus session is distraction-free only if none of that user's notification timestamps falls inside the session's interval, with both endpoints counted as inside. Given every session and every notification, report which sessions were distraction-free.
S and A -- the number of focus sessions and the number of notification records.S lines contains four tokens sessionId userId start end: a focus session belonging to userId, running from start to end inclusive. Session ids are pairwise distinct.A lines contains two tokens userId timestamp: a notification delivered to userId at that time.Print the id of every distraction-free session, one per line, in ascending numeric order. If no session is distraction-free, print nothing.
Example 1
Input
2 3 101 alice 100 200 102 bob 50 60 alice 150 alice 250 bob 70
Expected
102
Explanation
Session 101 belongs to alice and runs [100, 200]; alice has a notification at 150, which falls inside that window, so session 101 is not distraction-free. Session 102 belongs to bob and runs [50, 60]; bob's only notification is at 70, which is outside [50, 60], so session 102 is distraction-free. Only 102 is printed.
Example 2
Input
2 2 1 u1 10 20 2 u1 30 40 u1 20 u1 41
Expected
2
Explanation
Session 1 runs [10, 20] for u1; u1 has a notification at exactly 20, which counts as inside the inclusive window, so session 1 is disqualified. Session 2 runs [30, 40]; u1's other notification is at 41, which is outside [30, 40], so session 2 is distraction-free.
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 →