My first instinct was union-find, which is right, but the part I fumbled was figuring out how to avoid the O(n^2) edge enumeration.
Sort intervals by start time, then sweep through them while maintaining the maximum end time seen so far. When the next interval's start exceeds the current max end, a new component begins; otherwise, it connects to the current component. Track the size of each component and return the maximum.
Pro tip: Clarify that intervals touching at endpoints (e.g., [1,2] and [2,3]) are considered overlapping, as this edge case can change the component structure. Also, mention that the sweep line approach naturally handles this if you use 'start <= max_end' for overlap.
Sort all intervals by their start time in ascending order. This is the key to achieving O(n log n) time complexity.
Set current component size to 0, max component size to 0, and max_end to -infinity. These will track the current component and the overall maximum.
For each interval in sorted order, if its start <= max_end, it overlaps with the current component, so increment the component size and update max_end. Otherwise, finalize the previous component, update the global maximum, and start a new component with size 1 and max_end = end.
After the loop, update the global maximum with the last component's size and return it.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.