Simple Array Sum — Hackerrank
Given an array of N integers, can you find the sum of its elements?
Input Format
The first line contains an integer, N, denoting the size of the array.
The second line contains N space-separated integers representing the array’s elements.
Sample Input
6
1 2 3 4 10 11
Sample Output
31
Explanation
We print the sum of the array’s elements, which is: 1+2+3+4+10+11 = 31
.
My Solution:
Here’s my Python solution. It’s pretty straightforward. We just use the built-in function sum()
on the list of integers that we get from the input()
I also did the same problem in C++. Here, we loop over all the input integers and just store their sum in our output
variable.
I would welcome any queries or suggestions to improve this algorithm. Feel free to reach out to me.
If you want me to solve some specific problem, you can ask me here.