Posts

Showing posts with the label google

2332. The Latest Time to Catch a Bus

https://leetcode.com/problems/the-latest-time-to-catch-a-bus/description/ You are given a  0-indexed  integer array  buses  of length  n , where  buses[i]  represents the departure time of the  i th  bus. You are also given a  0-indexed  integer array  passengers  of length  m , where  passengers[j]  represents the arrival time of the  j th  passenger. All bus departure times are unique. All passenger arrival times are unique. You are given an integer  capacity , which represents the  maximum  number of passengers that can get on each bus. When a passenger arrives, they will wait in line for the next available bus. You can get on a bus that departs at  x  minutes if you arrive at  y  minutes where  y <= x , and the bus is not full. Passengers with the  earliest  arrival times get on the bus first. More formally when a bus arrives, either: If...

323. Number of Connected Components in an Undirected Graph

Image
https://leetcode.com/problems/number-of-connected-components-in-an-undirected-graph/description/ You have a graph of  n  nodes. You are given an integer  n  and an array  edges  where  edges[i] = [a i , b i ]  indicates that there is an edge between  a i  and  b i  in the graph. Return  the number of connected components in the graph .   Example 1: Input: n = 5, edges = [[0,1],[1,2],[3,4]] Output: 2 Example 2: Input: n = 5, edges = [[0,1],[1,2],[2,3],[3,4]] Output: 1   Constraints: 1 <= n <= 2000 1 <= edges.length <= 5000 edges[i].length == 2 0 <= a i <= b i < n a i != b i There are no repeated edges. ---- Related problems https://sweip.blogspot.com/2020/05/200-number-of-islands.html --- Time - O(V + E) Space - O(V + E) --- ---

1229. Meeting Scheduler

https://leetcode.com/problems/meeting-scheduler/description/ Given the availability time slots arrays  slots1  and  slots2  of two people and a meeting duration  duration , return the  earliest time slot  that works for both of them and is of duration  duration . If there is no common time slot that satisfies the requirements, return an  empty array . The format of a time slot is an array of two elements  [start, end]  representing an inclusive time range from  start  to  end . It is guaranteed that no two availability slots of the same person intersect with each other. That is, for any two time slots  [start1, end1]  and  [start2, end2]  of the same person, either  start1 > end2  or  start2 > end1 .   Example 1: Input: slots1 = [[10,50],[60,120],[140,210]], slots2 = [[0,15],[60,70]], duration = 8 Output: [60,68] Example 2: Input: slots1 = [[10,50],[60,120],[140,210]], ...