TikTok is hosting a livestream event with popular creators. Each creator has submitted their preferred start and end times for their part in the livestream. Only one creator can livestream at the event at a time.
Given an array of available time intervals where intervals[i] = [start(i), end(i)], determine if all creators could attend all.
Constraints:
0 <= start(i) < end(i) <= 10^6Length of each interval will be 2
Example 1:
Input: intervals = [[0,30],[5,10],[15,20]]
Output: false
Example 2:
Input: intervals = [[7,10],[2,4]]
Output: true
Follow: Now, TikTok changes minds and wants to fit all the creators to the livestream event. In that case, how many livestream rooms should they provide? Return the minimum number of livestream rooms.
Example 1:
Input: intervals = [[0,30],[5,10],[10,20]]
Output: 2
Example 2:
Input: intervals = [[7,10],[2,4]]
Output: 1
Example 3:
Input: [[7,10],[2,4],[7,10],[2,4]]
Output: 2
Example 4:
Input: [[0,30],[15,45],[30,60]]
Output: 2
Example 5:
Input: [[0,30],[15,45],[45,60],[45,70]]
Output: 2
Example 5:
Input: [[0,45],[15,30],[45,60],[45,70]]
Output: 2
This is a classic interval-overlap problem. The first part asks whether all creators can be scheduled in one livestream room without conflicts; the follow-up asks for the minimum number of rooms needed, which is the maximum number of overlapping intervals at any time. A standard solution is to sort intervals by start time and use a min-heap of end times to reuse rooms whenever possible. Boundary cases matter, such as whether one interval ending at time t can be followed by another starting at t, as shown by the examples.