Sessionize Events
MediumData EngineeringArraySorting
Description
Given sorted event timestamps and a gap threshold, assign each event a session id starting at 0. A new session begins whenever the gap from the previous event is strictly greater than the threshold.
Examples
Input:
[1,2,3,10,11], 2Output:
[0,0,0,1,1]Explanation:
Events flow into the same session until a gap larger than the threshold opens, which starts the next session.
Input:
[1,2,3], 5Output:
[0,0,0]Explanation:
Events flow into the same session until a gap larger than the threshold opens, which starts the next session.
Input:
[1,10,20], 1Output:
[0,1,2]Explanation:
Events flow into the same session until a gap larger than the threshold opens, which starts the next session.
Constraints
- •
1 ≤ length ≤ 10⁴ - •
timestamps sorted ascending