DSAAGP50 - Editorial

Problem Link - Sum of Array elements in Arrays

Problem Statement:

Calculate the sum of all the array elements

Approach:

  • Initialize a variable with 0 to store the sum (let’s call it sum).
  • Iterate through the array and add each element to sum.
  • The variable sum will contain the sum of all elements after the loop finishes.

Complexity:

  • Time Complexity: O(N) N is the size of array. We are traversing through the whole array.
  • Space Complexity: O(1) No extra space used.