Pre-Calculus for Programmers
When are we both free?
Two people each give you the window they are free in, as minutes counted from midnight. A window is a pair [start, end] and it includes both ends. You want the window in which both of them are free, which is the intersection of the two intervals.
Return that shared window as a pair [start, end], or an empty list if there is no moment they are both free.
Input: a = [540, 720], b = [660, 900]
The shared start is the later of the two starts: max(540, 660) = 660
The shared end is the earlier of the two ends: min(720, 900) = 720
660 is not after 720, so the window is real.
Output: [660, 720]Input: a = [0, 100], b = [200, 300] Output: []
Input: a = [100, 200], b = [120, 150] Output: [120, 150]
Input: a = [100, 200], b = [200, 300] Output: [200, 200]a and b each hold exactly two values, with the start no later than the end.Run your code to see how it does on the examples. Submit also runs the hidden cases.