Dsa
Prefix Sum
Easy
The Warehouse Weight Pivot
In a logistics center, items are placed in a single row. Each item has a specific weight. Your task is to find the 'Weighted Pivot Index'. This is the 0-indexed position 'i' where the sum of weights of all items to the left of 'i' is exactly twice the sum of weights of all items to the right of 'i'. If multiple such indices exist, return the leftmost one. If no such index exists, return -1. Note: The sums do not include the weight of the item at index 'i' itself. The sum of zero elements is 0.
Example:
Input:
5
6 0 2 1 2
Output:
2
Explanation:
Index 2 has value 2. Left sum (6+0) = 6. Right sum (1+2) = 3. Since 6 = 2 * 3, index 2 is the pivot.
Key concepts
prefix_sumarray_partition
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now