Long Break
Updated
Problem statement
You are organizing an event with several presentations in one room. The event runs from time 0 to time t. Presentation i runs from start[i] to finish[i]. The presentations do not overlap, but one may start right when the previous one ends. Any time with no presentation is free time for networking.
You may move up to k presentations to a different start time. A moved presentation keeps its length and must stay inside the event. The order of the presentations cannot change, and they still may not overlap. Your goal is to make the longest stretch of free time as long as you can. Return that length.
Complete the function maxNetworkingTime in the editor.
maxNetworkingTime has the following parameters:
int t: the time the event endsint[] start: the start time of each presentationint[] finish: the end time of each presentationint k: the most presentations you may move
The function returns an int: the longest stretch of free time you can make.
Function
maxNetworkingTime(t: int, start: int[], finish: int[], k: int) → intExamples
Example 1
t = 15start = [4, 6, 7, 10]finish = [5, 7, 8, 11]k = 2return = 6
The event runs from time 0 to t = 15. There are n = 4 presentations, at 4 to 5, 6 to 7, 7 to 8 and 10 to 11. You may move up to k = 2 of them.
Without moving anything, the free stretches are 0 to 4, 5 to 6, 8 to 10 and 11 to 15. The longest has length 4.
Move the last presentation (10 to 11) earlier, to 8 to 9. Now the free time after it runs from 9 to 15, which is 6 long. Moving the first presentation later gives only 5. The longest free stretch you can make is 6.
Constraints
1 ≤ t ≤ 1091 ≤ n ≤ 105, wherenis the length ofstartandfinish0 ≤ k ≤ n0 ≤ start[i] < finish[i] ≤ t- The presentations are listed in time order and do not overlap:
finish[i] ≤ start[i + 1]
More WeRide interview questions
Similar questions at other companies
- Count Equal-Distinct Character PartitionsInfosys · OAInfosys interview questions
- Maximum Order VolumeSnowflake · OASnowflake interview questions
- Max Subarray Filled With ZerosGoogle · OAGoogle interview questions
- Smart Gardener (Intuit India)Intuit · OAIntuit interview questions
- Cinema ShowsAmazon · OA
- Fewest Fountains to Water the GardenDocuSign · OADocuSign interview questions
- Minimum Length After Removing Arithmetic TriplesMedia.net · PHONE SCREEN
- New 21 Game ProbabilityUiPath · PHONE SCREEN
- Deployment Window SchedulerStripe · OAStripe interview questions
- Largest Consistent Visiting GroupAuxoAI · OA