Optimal Warehouse Loading
Meesho's logistics team aims to maximize the efficiency of product delivery. Each delivery truck has strict maximum weight and volume capacities. Given a list of various products, each with its own weight, volume, and associated market value, the challenge is to select an optimal subset of products to load into a truck. The goal is to maximize the total value of loaded products while strictly adhering to both the weight and volume constraints of the truck.
Implement a function maxProductLoadingValue that calculates the maximum total value of products that can be loaded into a truck.
Function Signature:
function maxProductLoadingValue(maxWeight: number, maxVolume: number, products: Product[]): number
Parameters:
maxWeight: An integer representing the maximum weight capacity of the truck.maxVolume: An integer representing the maximum volume capacity of the truck.products: An array of objects, where each object represents a product and has the following properties:
weight: An integer representing the product's weight.volume: An integer representing the product's volume.value: An integer representing the product's market value.Return Value:
maxWeight and maxVolume capacities.products list, the maximum value is 0.Examples
Example 1
Input:
maxWeight = 10, maxVolume = 10, products = [{weight: 2, volume: 3, value: 5}, {weight: 3, volume: 4, value: 7}, {weight: 5, volume: 6, value: 10}]
Output:
17
Note:
To maximize value:
Possible combinations within (10,10) capacity:
The maximum value is 17 (by taking Product 2 and Product 3).
Example 2
Input:
maxWeight = 5, maxVolume = 5, products = [{weight: 6, volume: 2, value: 10}, {weight: 2, volume: 6, value: 12}, {weight: 3, volume: 3, value: 7}]
Output:
7
Note:
Given capacities (5,5):
Example 3
Input:
maxWeight = 10, maxVolume = 10, products = []
Output:
0
Note:
With an empty list of products, no items can be loaded, resulting in a total value of 0.
Constraints
1 <= maxWeight, maxVolume <= 5000 <= products.length <= 1001 <= product.weight <= maxWeight1 <= product.volume <= maxVolume1 <= product.value <= 1000maxWeight, maxVolume, product.weight, product.volume, product.value) are integers.Loading editor...