Problem Statement
We need to know how long a customer may be forced to wait before he or she can place an order. Given a script that lists each customer for a typical day, we want to calculate the maximum customer waiting time. Each customer in the script is characterized by an arrival time (measured in minutes after the store opened) and a service duration (the number of minutes between ordering and getting the food).
Create a class BigBurger that contains method maxWait that is given a
If multiple customers arrive at the same time they will all join the line at the same time, with the ones listed earlier ahead of ones appearing later in the list.
Definition
- Class:
- BigBurger
- Method:
- maxWait
- Parameters:
- int[], int[]
- Returns:
- int
- Method signature:
- int maxWait(int[] arrival, int[] service)
- (be sure your method is public)
Constraints
- arrival will contain between 1 and 50 elements inclusive
- service will contain the same number of elements as arrival
- the elements of arrival will be in non-decreasing order
- each element of arrival will be between 1 and 720 inclusive
- each element of service will be between 1 and 15 inclusive
Examples
{3,3,9}
{2,15,14}
Returns: 11
Two customers arrive at time 3. The first one waits 0 time, orders, and is served after 2 minutes, leaving at time 5. The second one then orders and is served at time 20. Meanwhile a customer arrives at time 9 and waits until the second customer leaves. This last customer then orders at time 20, and is served and leaves at time 20+14 = 34. The first customer waited 0 minutes, the second waited 2 minutes (from time 3 to time 5), and the last customer waited 11 minutes (from time 9 to time 20).
{182}
{11}
Returns: 0
The first customer never needs to wait.
{2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2}
{15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15}
Returns: 735
{2,10,11}
{3,4,3}
Returns: 3
The third customer needs to wait from time 11 to time 14. Neither of the other customers needs to wait at all.
{2,10,12}
{15,1,15}
Returns: 7
The second customer waits the longest.
{720,720,720,720,720,720,720,720,720,720,720,720,720,720,720,720,720,720,720,720,720,720,720,720,720,720,720,720,720,720,720,720,720,720,720,720,720,720,720,720,720,720,720,720,720,720,720,720,720,720}
{15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15,15}
Returns: 735
{5,5,100,100,200,200,300,300,400,400}
{3,12,9,1,4,5,1,9,8,15}
Returns: 9
{3,3,3,700,700,700}
{12,3,9,13,1,15}
Returns: 15
{3,7,15,15,20,29,40,41,42,43,100,103,103,109,344,703,707,708}
{3,9,6,3,6,8,2,12,5,3,6,8,8,3,9,11,1,1}
Returns: 16
{9}
{3}
Returns: 0
{100,200,300,400,500,600,700}
{1,2,3,4,5,6,7}
Returns: 0
{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}
{15,1,1,1,1,1,1,1,1,1,1,1,1,1,1}
Returns: 14
{1,2,3,4,5,6,7,8,9,10,11,12,13,14,15}
{15,1,1,1,1,1,1,1,2,1,1,1,1,1,1}
Returns: 15
{1,2,3,4,5,7,8,9,10,11,12,13,14,15}
{15,1,1,1,1,1,1,1,3,1,1,1,1,1}
Returns: 15
{1,2,3,4,5,6,7,7,7,10,11,12,13,14,15}
{15,1,1,1,1,1,1,1,1,1,1,1,1,1,1}
Returns: 16
{1,2,3,4,7,7,7,7,10,11,12,13,14,15}
{15,1,1,1,3,3,2,3,1,1,1,1,1,1}
Returns: 20
{ 2, 10, 12 }
{ 15, 1, 5 }
Returns: 7
{ 1, 2, 3, 4, 5, 6, 7, 8, 9 }
{ 1, 1, 1, 1, 1, 10, 3, 6, 9 }
Returns: 16
{ 7, 7, 7, 7 }
{ 10, 15, 8, 10 }
Returns: 33
{ 1, 1, 1 }
{ 3, 2, 2 }
Returns: 5
{ 3, 3, 5, 6, 6 }
{ 3, 3, 3, 10, 10 }
Returns: 16
{ 720, 720, 720, 720, 720, 720, 720, 720, 720, 720, 720, 720, 720, 720, 720, 720, 720, 720, 720, 720, 720, 720, 720, 720, 720, 720, 720, 720, 720, 720, 720, 720, 720, 720, 720, 720, 720, 720, 720, 720, 720, 720, 720, 720, 720, 720, 720, 720, 720, 720 }
{ 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15 }
Returns: 735
{ 3, 5, 5 }
{ 1, 3, 1 }
Returns: 3