Running Sum of Purchases
Tracking the cumulative revenue of a market ledger is a core task for any business. In Running Sum of Purchases, you’re given a list of purchase values. Your goal is to return a New List where each entry captures the total sum immediately after that transaction was processed. This offers an instant snapshot of how earnings (or refunds) accumulate moment by moment throughout the day!
The "secret sauce" here is Iterative Accumulation. You start with a running counter at zero. As you walk through the input list, you add the current purchase to your counter and store the result in your new array. If a value is negative (like a discount), it still joins the sequence and reduces the total. Empty lists should return an empty result set. This is a fundamental pattern for financial reporting and data analysis, turning a simple loop into a precise tool for monitoring progress and balance in real-time professional environments! Return the completed list for the market owner.
Examples
The running totals after each purchase are 1, 3, 6, and 10.
Each purchase adds 1, so the running sum increments steadily.
The cumulative totals reflect how each purchase increases the balance.
Algorithm Flow

Best Answers
import java.util.*;
class Solution {
public Object running_sum(Object nums) {
int[] arr = (int[]) nums;
List<Integer> r = new ArrayList<>(); int t = 0;
for (int n : arr) { t += n; r.add(t); }
return r;
}
}Comments (0)
Join the Discussion
Share your thoughts, ask questions, or help others with this problem.
