Suppose we have a list of intervals, where each interval is like [start, end] this is representing start and end times of an intervals (inclusive), We have to find their intersection, i.e. the interval that lies within all of the given intervals.
So, if the input is like [[10, 110],[20, 60],[25, 75]], then the output will be [25, 60]
To solve this, we will follow these steps −
Let us see the following implementation to get better understanding −
class Solution: def solve(self, intervals): start, end = intervals.pop() while intervals: start_temp, end_temp = intervals.pop() start = max(start, start_temp) end = min(end, end_temp) return [start, end] ob = Solution() intervals = [[10, 110],[20, 60],[25, 75]] print(ob.solve(intervals))
[[10, 110],[20, 60],[25, 75]]