LeetCode Solutions/July 2022 LeetCoding Challenge/Maximum Units on a Truck.java
<filename>LeetCode Solutions/July 2022 LeetCoding Challenge/Maximum Units on a Truck.javaclass Solution {
    public int maximumUnits(int[][] boxTypes, int truckSize) {
        Arrays.sort(boxTypes, (a,b) -> b[1] - a[1]);
        int maxNumberOfUnits = 0;
        for(int[] b : boxTypes){
            int count = Math.min(b[0], truckSize);
            maxNumberOfUnits += count * b[1];
            truckSize -= count;
			if(truckSize == 0){
                return maxNumberOfUnits;
            }
        }
        return maxNumberOfUnits;
    }
}