← Back to Games

Contribution Kingdom

Learn the contribution technique for sum of all subarray sums!

🎯 The Magic Formula

contribution[i] = arr[i] × (i + 1) × (n - i)
Each element appears in multiple subarrays. Instead of summing all subarrays,
we calculate how many times each element contributes to the total sum!
-
Sum of All Subarray Sums

Click any element to see its contribution breakdown