← Back to Games

Sum Stream

Compare nested-loop sum vs prefix-sum optimization!

Nested Loop
O(n³) total
Prefix Sum
O(n²) total
🐢 Nested Loop Method O(n) per sum

For each subarray, iterate through all elements and add them up.

Operations: 0
🚀 Prefix Sum Method O(1) per sum

Precompute prefix sum, then calculate range sum with one subtraction.

Operations: 0
Original Array
Current Subarray Sum
-
Select a mode and click "Next Sum" to start
Subarray Elements Sum Operations