Calculate Peak Delivery Time
At Zomato, optimizing delivery logistics is crucial for customer satisfaction and operational efficiency. One challenge is identifying periods when both restaurants are experiencing high demand and delivery partners are readily available. This problem focuses on calculating the total duration of these 'peak delivery' windows to help in resource allocation and demand forecasting.
You are given two lists of time intervals: one representing periods when a restaurant anticipates high demand, and another representing periods when delivery partners are available. Your task is to find the total combined duration (in minutes) when both the restaurant is experiencing high demand and delivery partners are available.
Input:
restaurantIntervals: An array of [start, end] tuples, where start and end are integers representing minutes from midnight (0 to 1440). Each interval [start, end) is inclusive of start and exclusive of end. These represent periods of high restaurant demand.deliveryPartnerIntervals: An array of [start, end] tuples, in the same format as restaurantIntervals. These represent periods when delivery partners are available.Output:
[start, end) means start <= time < end.0.[100, 150) has a duration of 50 minutes.Examples
Example 1
Input:
restaurantIntervals = [[900, 1000], [1100, 1200]], deliveryPartnerIntervals = [[950, 1050], [1030, 1130]]
Output:
80
Note:
Restaurant is available from 900-1000 and 1100-1200. Delivery partners are available from 950-1050 and 1030-1130. The shared availability periods are [950, 1000) and [1100, 1130), summing to 50 + 30 = 80 minutes.
Example 2
Input:
restaurantIntervals = [[900, 1100]], deliveryPartnerIntervals = [[950, 1000], [980, 1050]]
Output:
100
Note:
Restaurant is available from 900-1100. Delivery partners are available from 950-1000 and 980-1050. The shared availability periods are [950, 1000) and [980, 1050), which merge into a single continuous period of [950, 1050), summing to 100 minutes.
Example 3
Input:
restaurantIntervals = [[100, 200]], deliveryPartnerIntervals = [[300, 400]]
Output:
0
Note:
There are no overlapping times when both the restaurant is available and delivery partners are available.
Constraints
0 <= start < end <= 1440 for all intervals.restaurantIntervals (N) and deliveryPartnerIntervals (M) will be between 0 and 10^4.[start, end) where start and end are integers.[2300, 100]).Loading editor...