hi, let Avik connect you.
** You can give your thought about this content and request modifications if needed from Ask For Modifications page. Thank You.
** You can check all the posts on the Posts page.
** More about me in the About Me section.
Complete Sum
Problem: Complete Sum
Problem Link: www.codingninjas.com/codestudio/problems/complete-sum_3161880
Companies Asked: Microsoft
Approach:
Traverse through the given array.
Calculate cumulative sum. That is, for each ith number, sum[i] = sum[i-1] + a[i].
Return sum array.
Time and Space Complexity:
Time Complexity: O(N)
Space Complexity: O(1)
Code [C++]
Code [C++]
#include <bits/stdc++.h>
vector<int> completeSum(vector<int> &a, int n) {
for(int i=1; i<n; i++){
a[i] = a[i-1] + a[i];
}
return a;
}