"engagement" is a very important metric for Pinterest. Given an array of start times and end times for pins, write an algorithm that returns number of engagements for time intervals. Example input [[0,5],[1,2],[3,7]] -> [0,1]:1, [1,2]:2, [2,3]:1, [3,5]:2, [5,7]:1.
Asked in the phone screen stage.
Implement def count_engagements(intervals):. Each interval is [start, end] with start < end, and intervals use half-open semantics [start, end). Return a list of [left, right, count] entries for every consecutive pair of distinct boundary times, including entries with count 0. Return [] when no intervals are provided.
def count_engagements(intervals):