Given a cargo ship with a list of crates of different weights, determine if it's possible to balance the cargo by dividing it into two parts with equal total weight. The division can be done at any point in the list of crates.
Explanation: Step-by-step: with input [10, 20, 40], we calculate the prefix sum array as [10, 30, 70]. We then check if the sum of the prefix sum array from index 0 to the middle index is equal to the sum of the prefix sum array from the middle index + 1 to the end. Since 10 + 30 is not equal to 70, we return false.
Explanation: Step-by-step: with input [1, 2, 3, 4, 5], we calculate the prefix sum array as [1, 3, 6, 10, 15]. We then check if the sum of the prefix sum array from index 0 to the middle index is equal to the sum of the prefix sum array from the middle index + 1 to the end. Since 1 + 3 + 6 is not equal to 10 + 15, we return false.
Master coding challenges related to Arrays and solve the [Backup] Cargo Ship Balancing problem optimally.
No dry run loaded.
🚀 Practice this problem
Run code, get AI hints & track streak