Live Batches
Masterclasses
Menu
Free Courses
Account
Login / Sign Up

Sum of Array Elements

Easy Acceptance 58.00% Points 20.00

You are given an array of integers. Your task is to calculate the sum of all elements present in the array and return the sum.

Examples
Example 1

Example 1

Input: arr[] = [1 2 3 4 5]

Output: 15

Explanation: 1 + 2 + 3 + 4 + 5 = 15

Example 2

Example 2

Input: arr[] = [10 20 30]

Output: 60

Explanation: 10 + 20 + 30 = 60

Example 3

Example 3

Input: arr[] = [5 -2 7]

Output: 10

Explanation: 5 + (-2) + 7 = 10

Hints
Hint 1
N/A
Constraints
  • 1 <N<105
  • -109 < arr[i] < 109
Companies
Samsung Mastercard Media.net
Topics
Recursion
Solution.cs C#JavaPythonC++Javascript

Unlock the code editor

Sign in to write, run, and submit your solution against the full test suite.

  • Run code against sample & hidden test cases
  • Save submissions and track your streak
  • Compare with editorial & community solutions