Running Sum Of 1d Array LeetCode

 Problem Link:


https://leetcode.com/problems/running-sum-of-1d-array/


(It is also the problem of the day for 01-06-2022)


Solution:


class Solution {

    public int[] runningSum(int[] nums) {

        int sum=0;

        for(int i=0;i<nums.length;i++){

            sum=sum+nums[i];

            nums[i]=sum;

        }

        return nums;

    }

}



Time Complexity: O(N)[LeetCode Time:0ms faster than 100%]

Space Complexity: O(N)

Auxiliary Space: O(1)[LeetCode memory usage of 39MB less than 100%]

Total Test Cases:53


Approach Used:


Here we will traverse the array and simultaneously keep on incrementing the value of the sum variable by arr elements value.

Later we will modify the existing array element by that sum value.

Here sum value at index i means the sum of all elements from 0 to i.




"Thanks For Reading.😇"

"Share Further To Increase Knowledge Treasure.😊"

Comments

Popular posts from this blog

Solutions Of Practice Questions Dated 01-06-2022

CODEFORCES SPY DETECTED ROUND 713

Maximum Winning Score Geeks For Geeks