Maximum Units on a Truck Problem
Maximum Units on a Truck Problem — ExecCode Easy DSA Practice
Solve the Maximum Units on a Truck problem on ExecCode. Free online easy DSA practice in Arrays - Basics. Write and run code in Java, C++, Python — no signup required to run.
Problem description
Description You are given a 2D array boxTypes, where boxTypes[i] = [numberOfBoxesi, numberOfUnitsPerBoxi]:. Your task is to compute the required answer and return the maximum total number of units that can be put on the truck. You are assigned to put some amount of boxes onto one truck. - numberOfBoxesi is the number of boxes of type i. - numberOfUnitsPerBoxi_is the number of units in each box of the type i. You are also given an integer truckSize, which is the maximum number of boxes that can be put on the truck.
Examples
Input {"boxTypes": [[1, 3], [2, 2], [3, 1]], "truckSize": 4}; Output 8. Input {"boxTypes": [[1, 1], [2, 2], [3, 3], [4, 4]], "truckSize": 1}; Output 4. Input {"boxTypes": [[2, 1], [4, 4], [3, 3]], "truckSize": 5}; Output 19
Constraints
1 <= boxTypes.length <= 1000 1 <= numberOfBoxesi, numberOfUnitsPerBoxi <= 1000 1 <= truckSize <= 10^6
Practice Maximum Units on a Truck free on ExecCode. Browse DSA problems, topic map, and placement guides.