How to implement an immutable range sum query in LeetCode?