You are viewing a single comment's thread. Return to all comments →
Can you tell me how the logic works?
I'm new and have many to learn.
If you already have the sum of a subarray (like the starred elements in [***___]), then you can get sum of the subarray with indices shifted right by 1 (for the previous example, [_***__]) by adding one element and subtracting another.
Prince_sai's solution gets O(n) runtime in a different way: a cumulative sum array.