Posts

Showing posts with the label event scan

391 · Number of Airplanes in the Sky

  391 · Number of Airplanes in the Sky Description Given an list  interval , which are taking off and landing time of the flight. How many airplanes are there at most at the same time in the sky? If landing and taking off of different planes happen at the same time, we consider landing should happen at first. Example Example 1: Input : [(1, 10), (2, 3), (5, 8), (4, 7)] Output : 3 Explanation : The first airplane takes off at 1 and lands at 10 . The second ariplane takes off at 2 and lands at 3 . The third ariplane takes off at 5 and lands at 8 . The forth ariplane takes off at 4 and lands at 7 . During 5 to 6 , there are three airplanes in the sky. Example 2: Input: [( 1 , 2 ), ( 2 , 3 ), ( 3 , 4 )] Output: 1 Explanation: Landing happen before taking off. --- Clarifying questions What is expected when takeoff and land times are same Intuition Event scan algorithm Sort events by time Corner case when time is same, put land times first, so high water mark is ...

759. Employee Free Time

https://leetcode.com/problems/employee-free-time/ https://github.com/openset/leetcode/tree/master/problems/employee-free-time We are given a list  schedule  of employees, which represents the working time for each employee. Each employee has a list of non-overlapping  Intervals , and these intervals are in sorted order. Return the list of finite intervals representing  common, positive-length free time  for  all  employees, also in sorted order. Example 1: Input: schedule = [[[1,2],[5,6]],[[1,3]],[[4,10]]] Output: [[3,4]] Explanation: There are a total of three employees, and all common free time intervals would be [-inf, 1], [3, 4], [10, inf]. We discard any intervals that contain inf as they aren't finite.   Example 2: Input: schedule = [[[1,3],[6,7]],[[2,4]],[[2,5],[9,12]]] Output: [[5,6],[7,9]]   (Even though we are representing  Intervals  in the form  [x, y] , the objects inside are  Intervals , not lists or arr...

1094. Car Pooling

https://leetcode.com/problems/car-pooling/ You are driving a vehicle that has  capacity  empty seats initially available for passengers.  The vehicle  only  drives east (ie. it  cannot  turn around and drive west.) Given a list of  trips ,  trip[i] = [num_passengers, start_location, end_location]  contains information about the  i -th trip: the number of passengers that must be picked up, and the locations to pick them up and drop them off.  The locations are given as the number of kilometers due east from your vehicle's initial location. Return  true  if and only if it is possible to pick up and drop off all passengers for all the given trips.  Example 1: Input: trips = [[2,1,5],[3,3,7]] , capacity = 4 Output: false Example 2: Input: trips = [[2,1,5],[3,3,7]] , capacity = 5 Output: true Example 3: Input: trips = [[2,1,5],[3,5,7]] , capacity = 3 Output: true Example 4:...