BackmediumTrees Cred

Jungle Supply Chain Optimization Solution

Problem Statement

In a jungle expedition supply chain, cargo is transported through a network of trees, where each tree represents a supply hub. The cargo is loaded and unloaded at each hub, and the total weight of cargo at each hub must not exceed its capacity. The supply chain manager needs to determine the minimum number of cargo units that can be transported through the network without exceeding the capacity of any supply hub.

Example 1
Input
cargo_units = [[1], [2], [3]], capacity = 4
Output
3

Explanation: Step-by-step: with input cargo_units = [[1], [2], [3]] and capacity = 4, we first sort the cargo units by weight in descending order. Then, we iterate through the sorted cargo units and load them into the supply hubs until the capacity is reached. In this case, we can load 1 cargo unit of weight 3, then 1 cargo unit of weight 2, and finally 1 cargo unit of weight 1 without exceeding the capacity. Therefore, the minimum number of cargo units that can be transported is 3.

Example 2
Input
cargo_units = [[1, 2], [3, 4]], capacity = 5
Output
2

Explanation: Step-by-step: with input cargo_units = [[1, 2], [3, 4]] and capacity = 5, we first sort the cargo units by weight in descending order. Then, we iterate through the sorted cargo units and load them into the supply hubs until the capacity is reached. In this case, we can load 1 cargo unit of weight 4 and 1 cargo unit of weight 1 without exceeding the capacity. Therefore, the minimum number of cargo units that can be transported is 2.

Live Compiler
Loading...
Test Cases & Output
🔒 Sign up to run your code

🚀 Practice this problem

Run code, get AI hints & track streak

Sign Up Free