Easy Difficulty
Runningsum of 1d Array

Array

easy

Running Sum of 1d Array

Link to algo

The problem of Running Sum of 1d Array in Javascript involves calculating the running sum of an input array of integers, where the running sum at each index is the sum of all elements up to that index (inclusive).

Here's an example of how to solve this problem in Javascript using a simple loop:

function runningSum(nums) {
  let sum = 0;
  return nums.map((num) => (sum += num));
}

This solution uses the map() function to iterate through each element of the input array and calculates the running sum by adding the current element to a variable sum, which keeps track of the sum up to the current index.

The time complexity of this solution is O(n), where n is the length of the input array, since it only needs to iterate through the array once. The space complexity is also O(n), since it creates a new array to store the running sums.