You are given a list of user engagement intervals. Each interval is represented as [start, end] where start is the inclusive time a user began engaging and end is the inclusive time the user stopped engaging. Your task is to compute a time-series that shows the number of concurrent engagements at every moment. Instead of returning a value for every single time unit, you must output only the points in time when the running count changes, and you must output them in ascending order by time. Specifically, produce an array of [time, count] pairs such that:
To solve this efficiently you should apply a line-sweep: treat every start as a +1 event and every end+1 as a –1 event, sort all events by time (breaking ties so that all –1 events for a given time are processed before +1 events at the same time), sweep through the events while maintaining a running sum, and record the running sum whenever it differs from the previous recorded value.