BackmediumRecursion Atlassian

Interstellar Cargo Distribution Solution

Problem Statement

Given a cargo shipment with various package weights, determine the number of ways to distribute these packages evenly into two spacecraft, Starblade and NovaSpur, such that the total weight of packages in both spacecraft is equal.

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

Explanation: Step-by-step: with input [1, 2, 3, 4, 5], we calculate the total weight of packages, which is 15. Since 15 is odd, we cannot evenly distribute the packages between two spacecraft. Therefore, the number of ways to distribute the packages is 0.

Example 2
Input
[10, 10, 10, 10]
Output
1

Explanation: Step-by-step: with input [10, 10, 10, 10], we calculate the total weight of packages, which is 40. We can evenly distribute the packages between two spacecraft by placing 20 packages in each spacecraft. Therefore, the number of ways to distribute the packages is 1.

Constraints

  • 1 <= package_weights.length <= 20
  • 1 <= package_weights[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