Running Sum of 1D Array
This problem feels like a little puzzle you can solve one step at a time. In Running Sum of 1D Array, you are trying to work toward the right list by following one clear idea.
This one is about building the best total or working out a final amount. You may need to choose which values should be included and which ones should be skipped. Sometimes the biggest number is not the smartest first choice if it hurts the rest of the plan. The goal is to finish with the best overall total, not just one good moment.
For example, if the input is nums = [1,2,3,4], the answer is [1,3,6,10]. Example with input: nums = [1,2,3,4] Another example is nums = [3,1,2,10,1], which gives [3,4,6,16,17]. Example with input: nums = [3,1,2,10,1]
This is a friendly practice problem, but it still rewards careful reading. The key is thinking about the whole plan, not only one choice at a time.
Example Input & Output
Example with input: nums = [1,2,3,4]
Example with input: nums = [3,1,2,10,1]
Example with input: nums = [1,1,1,1,1]
Algorithm Flow

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