Student, Developer, Technology Advocate
Welcome to my personal website

Hackerrank Solution: Simple Array Sum

on Oct. 31, 2016, 9:49 p.m.

Given an array of 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.

Output Format
Print the sum of the array's elements as a single integer.

Sample Input
1 2 3 4 10 11

Sample Output



import sys

n = int(input().strip())
arr = [int(arr_temp) for arr_temp in input().strip().split(' ')]

while i < n:
total += arr[i]

The code listed above may or may not be the "best" solution. Please be advised that this is just the way I did it. There are normally thousands of different ways to solve the same programming problem. Find an error? Let me know in the contact form below.

Contact Me

Feel free to email me feedback, suggestions, notes, or to just say hello!