Describe how you would implement a script to fetch the most active workplaces, including criteria for activity, data sources, and performance considerations.
Treat each activity record as [workplace_id, timestamp]; activity is the number of records in the inclusive-exclusive interval [start, end). Implement active_workplaces(events, start, end, min_activity, k), returning up to k [workplace_id, count] pairs, ordered by count descending and workplace ID ascending for ties. The event array is the data source.
def active_workplaces(events, start, end, min_activity, k):