Description
Solutions
Submission
Maximum Order Volume ☎️
🤘 INTERN

During the day, a supermarket will receive calls from customers who want to place orders. The supermarket manager knows in advance the number of calls that will be attempted, the start time, duration, and order volume for each call. Only one call can be in progress at any one time, and if a call is not answered, the caller will not call back. The manager must choose which calls to service in order to maximize order volume. Determine the maximum order volume.

Function Description

Complete the function phoneCalls in the editor.

phoneCalls has the following parameter(s):

  1. int start[n]: the start times of each call
  2. int duration[n]: the durations of each call
  3. int volume[n]: the volumes of each order

Returns

int: the maximum possible volume of orders that can be received

Example 1:

Input:  start = [10, 5, 15, 18, 30], duration = [30, 12, 20, 35, 35], volume = [50, 51, 20, 25, 10]
Output: 76
Explanation:
Image above puts input data into a table 👆 The first call will start at time = 10, and last until time = 40. The second call will start at time = 5, and last until time = 17. The third call will start at time = 15, and last until time = 35. The fourth call will start at time = 18, and last until time = 53. The fifth call will start at time = 30, and last until time = 65. The first call completely overlaps the second and third calls, and partially overlaps the fourth and fifth calls. Choosing calls that do not overlap, and answering the 2nd and 4th calls leads to the maximum total order volume of 51 + 25 = 76.
Constraints:
    • 1 ≤ n ≤ 105
    • 1 ≤ start[i] ≤ 109
    • 1 ≤ duration[i] ≤ 109
    • 1 ≤ volume[i] ≤ 103
Thumbnail 0
Testcase

Result
Case 1

input:

output: