Posts

Showing posts with the label sort

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...

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]], ...

2268. Minimum Number of Keypresses

Image
 https://leetcode.com/problems/minimum-number-of-keypresses/description/ You have a keypad with  9  buttons, numbered from  1  to  9 , each mapped to lowercase English letters. You can choose which characters each button is matched to as long as: All 26 lowercase English letters are mapped to. Each character is mapped to by  exactly   1  button. Each button maps to  at most   3  characters. To type the first character matched to a button, you press the button once. To type the second character, you press the button twice, and so on. Given a string  s , return  the  minimum  number of keypresses needed to type  s  using your keypad. Note  that the characters mapped to by each button, and the order they are mapped in cannot be changed.   Example 1: Input: s = "apple" Output: 5 Explanation: One optimal way to setup your keypad is shown above. Type 'a' by pressing button 1 once. Type 'p' b...