Skip to main content

Command Palette

Search for a command to run...

Running Sum of 1d Array.

Published
1 min read
Running Sum of 1d Array.
G

As a Systems Engineer at Tata Consultancy Services, I deliver exceptional software products for mobile and web platforms, using agile methodologies and robust quality maintenance. I am experienced in performance testing, automation testing, API testing, and manual testing, with various tools and technologies such as Jmeter, Azure LoadTest, Selenium, Java, OOPS, Maven, TestNG, and Postman.

I have successfully developed and executed detailed test plans, test cases, and scripts for Android and web applications, ensuring high-quality standards and user satisfaction. I have also demonstrated my proficiency in manual REST API testing with Postman, as well as in end-to-end performance and automation testing using Jmeter and selenium with Java, TestNG and Maven. Additionally, I have utilized Azure DevOps for bug tracking and issue management.

Q - Given an array nums. We define a running sum of an array as runningSum[i] = sum(nums[0]…nums[i]). Return the running sum of nums.

LeetCode Problem: Link | Click Here

class Solution {
    public int[] runningSum(int[] nums) {
        // Get the length of the input array
        int numsLength = nums.length;

        // Create an array to store the running sum values
        int[] runningSum = new int[numsLength];

        // Initialize the first element of the runningSum array with the first element of nums array
        runningSum[0] = nums[0];

        // Initialize a temporary variable to keep track of the running sum
        int temp = nums[0];

        // Iterate through the nums array starting from the second element
        for (int i = 1; i < numsLength; i++) {
            // Calculate the running sum for each index i
            // Add the previous running sum (temp) with the current value in nums array
            runningSum[i] = temp + nums[i];

            // Update the temporary variable to store the current running sum for the next iteration
            temp = runningSum[i];
        }

        // Return the array containing the running sum values
        return runningSum;
    }
}

More from this blog

S

Software and Performance Testing Insights

462 posts

Results-Driven Agile QA Specialist | Expert in Mobile & Web Testing | Proficient in Test Planning, Execution, and Root Cause Analysis.