Problem Brief

Long Break

INTERNOA

You are organizing an event where there will be a number of presenters. The event starts at time 0 and time be allocated for networking at any time during the event when there is not a presentation being made. The presentations may not overlap as they are in the same room, but this allows them to run consecutively, without breaks. While the order of speeches cannot be changed, there is a maximum number given that indicates how many speeches may be rescheduled. Your goal is to maximize the length of the longest networking period you can arrange.

Function Description

Complete the function maxNetworkingTime in the editor.

maxNetworkingTime has the following parameters:

  • 1. int[] start: an array of integers indicating the start times of the presentations
  • 2. int[] finish: an array of integers indicating the end times of the presentations
  • 3. k: the maximum number of presentations that can be rescheduled
  • Returns

    int: the maximum length of the longest networking period that can be arranged

    1Example 1

    Input
    start = [4, 6, 7, 10], finish = [5, 7, 8, 11], k = 2
    Output
    6
    Explanation
    Example 1 illustration
    there are n = 4 presenters scheduled for the course of the event which begins at time 0 and ends at time t = 15. The meetings start at times start = [4, 6, 7, 10] and end at times finish = [5, 7, 8, 11]. You can rearrange up to k = 2 meetings. Green cells are free, marked with the hour number, and blue cells have a presentation scheduled, marked with presentation number. (Shown in the first line of colors in the image) In this case, we have 4 periods without speakers scheduled: [0-3], [5-6], [8-9], [11-14]. The meeting ends after hour 14. If the first meeting is shifted to an hour later, a break is created from 0 to 5 hours. If the last speech is moved up to 8, it will end at 9 leaving a break from 9 to 15. There is no point to moving the middle two speeches in this case. The longest break that can be achieved is 15 - 9 = 6 hours by moving the last speech to two hours earlier. The two options are illustrated in the option1 and option2 lines in the image above.

    Constraints

    Limits and guarantees your solution can rely on.

    Unkown for now. Will be sure to add once find them
    public int maxNetworkingTime(int[] start, int[] finish, int k) {
        // write your code here
    }
    
    Input

    start

    [4, 6, 7, 10]

    finish

    [5, 7, 8, 11]

    k

    2

    Output

    6

    Sign in to submit your solution.