Calculate the maximum work time (minutes) to assign to one worker?



Multiple “intervals” are to be given as tasks. Calculate the maximum work time (minutes) to assign to one worker

Implement the method “int Problem2#getMaxWorkingTime(List intervals)”.

  1. Return the maximum time to work on a
    task when one worker takes it.

  2. Time assignment unit shall be based
    on tasks. (i.e. Task assignment
    shall be either to complete the
    whole task, or to do nothing for

  3. The length of the interval, time
    required to complete the task, is
    calculated by subtracting “end time”
    from “start time”. (e.g. If [12:00,
    13:00] is given, the length of the
    task is 60 min.)

  4. Return 0 if the argument is null or
    an empty list.

In Figure 3 , work time is maximized when three tasks [“06:00”, “08:30”], [“09:00”, “11:30”], and [“12:30”, “14:00”], are assigned. Therefore, the answer is 390 (minutes).

Figure 3: An example of input and answer

6     7     8     9     10      11      12       13       14
----------------  ---------------            ---------------
            -------         --------------------------------

Intervals = [06:00-08:30], [08:00-09:00], [09:00-11:00], [09:00-11-30], [12:30-14:00], [10:30-14:00] (which is shown in figure 3 also)

Total Intervals = 6

What I have tried so far

To me it appears to as a problem whose answer I can find simply by subtracting the Interval with max end-time i.e 14:00 with Interval which has smallest start-time, say 14:00 minus 06:00 answer is 480 minutes (since 6 to 14 has 8 hours in it so 8*60 minutes = 480 minutes) but the correct answer is 390 minutes

Can any one please help me explaining how to solve this problem…?

The thing which I want to understand is out of 6 Intervals why only those 3 Intervals (mentioned above) is selected ?