When NOT to Use

Avoid forcing this pattern

Avoid forcing this pattern when:

  • Array changes frequently: Prefix sum requires O(n)O(n) rebuild after modifications. Use segment tree for dynamic arrays.
  • Single query only: For one range query, direct summation is simpler than building prefix array.
  • Non-sum operations: Prefix sums don't generalize to all operations.

Use segment trees for min/max queries. Remember: forcing a pattern where it doesn't fit leads to overcomplicated solutions. If you find yourself fighting the approach, step back and reconsider whether another technique works better.