#415 Maximum Truck Underload

Companies:
Sberbank
Themes:
AlgorithmsSortingPractice

A truck loading station needs an algorithm for distributing cargo among trucks. Load the cargo onto the trucks and then return the maximum amount of unused capacity:

private int calcTrucks(int[] weights, int trucksCount, int truckMaxCapacity) {
    ...
}

Parameters:

  • weights — array of cargo weights;
  • trucksCount — number of trucks;
  • truckMaxCapacity — maximum truck capacity.

Examples:

Input - [10, 100, 20, 30, 40, 10], 4, 100
Output - 90

Input - [10, 100, 20, 30, 40], 4, 100
Output - 0

Question review

Mentor
Answer as you would in a real interview. I’ll ask follow-up questions, then compare your answer with the reference answer and show your accuracy as a %.
Sign in to start the dialogue The mentor keeps the context of the current question and your previous messages.
Sign in