Posts

Showing posts with the label array

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  capacity  or fewer passengers are waiting for a bus, they will  all  get on the bus, or The  capacity  passengers with the  earliest  arrival

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]], slots2 = [[0,15],[60,70]], duration = 12 Output: []   Constraints: 1 <= slots1.length, slots2.length <

Package Boxing

https://app.codesignal.com/company-challenges/jet/SrM76w6eoxioTMiCK Before delivery, all orders at Jet are packed into boxes to protect them from damage. Consider a package  pkg  of a given size that needs to be packed into a box chosen from a list of available  boxes . The package should fit inside the box, keeping in mind that the size of the package should not exceed the size of the box in any dimension (note that the package can be rotated to fit and it can be positioned upside down). For the sake of efficiency, among the available boxes that fit, the one with smallest volume should be chosen. Given a package  pkg  and available  boxes , find the 0-based index of the smallest-by-volume box such that the package fits inside it, or return  -1  if there is no such box. Example For  pkg = [4, 2, 5]  and  boxes = [[4, 3, 5], [5, 2, 5]] , the output should be solution(pkg, boxes) = 1 . The package fits into both boxes, but the volume of the first one ( 4 * 3 * 5 = 60 ) is greater than th