BackmediumBacktracking Swiggy

Cargo Bay Organization Solution

Problem Statement

Given a list of cargo crates with their respective weights and a target number of cargo bays, organize the crates into the bays such that the total weight in each bay is as close to equal as possible, using backtracking to explore all possible configurations.

Example 1
Input
[10, 20, 30, 40, 50], 3
Output
True

Explanation: Step-by-step: We have 5 crates with weights 10, 20, 30, 40, 50. We want to distribute them into 3 bays. We can distribute them as follows: Bay 1: 10, 20, 30 (total weight 60), Bay 2: 40 (total weight 40), Bay 3: 50 (total weight 50). This configuration is valid, so the output should be True.

Example 2
Input
[1, 2, 3, 4, 5], 2
Output
True

Explanation: Step-by-step: We have 5 crates with weights 1, 2, 3, 4, 5. We want to distribute them into 2 bays. We can distribute them as follows: Bay 1: 1, 2, 3 (total weight 6), Bay 2: 4, 5 (total weight 9). This configuration is valid, so the output should be True.

Constraints

  • 1 <= k <= 10
  • 1 <= crates.length <= 16
  • 1 <= crates[i] <= 100
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