Simply Array Sum
Simply Array Sum
Simply Array Sum
NEW
PRACTICE CERTIFICATION COMPETE LEADERBOARD Search nayanaveeresh101
All Contests
MountBlue Job Challenge
Simple Array Sum
Function Description
Complete the simpleArraySum function in the editor below. It must return the sum of the array elements as an integer.
Input Format
The first line contains an integer, , denoting the size of the array.
The second line contains space-separated integers representing the array's elements.
Constraints
Output Format
Sample Input
1 2 3 4 10 11
Sample Output
31
Explanation
Submissions:
5114
Max Score:
10
Python 3
⚙
1 #!/bin/python3
2
3 import math
https://www.hackerrank.com/contests/mountblue-technologies/challenges/simple-array-sum 1/2
24/05/2022, 16:15 Simple Array Sum | MountBlue Job Challenge Question | Contests | HackerRank
4 import os
5 import random
6 import re
7 import sys
8
9 #
10 # Complete the 'simpleArraySum' function below.
11 #
12 # The function is expected to return an INTEGER.
13 # The function accepts INTEGER_ARRAY ar as parameter.
14 #
15
16 ▾ def simpleArraySum(ar):
17 x=0
18 ▾ for i in range(0,ar_count):
19 x = x + ar[i]
20 return x
21
22 ▾ if __name__ == '__main__':
23 fptr = open(os.environ['OUTPUT_PATH'], 'w')
24
25 ar_count = int(input().strip())
26
27 ar = list(map(int, input().rstrip().split()))
28
29 result = simpleArraySum(ar)
30
31 fptr.write(str(result) + '\n')
32
33 fptr.close()
34
Line: 2
Col: 1
Testcase 0 ✓
Input (stdin)
1 2 3 4 10 11
31
Expected Output
31
Contest Calendar
|
Interview Prep
|
Blog
|
Scoring
|
Environment
|
FAQ
|
About Us
|
Support
|
Careers
|
Terms Of Service
|
Privacy Policy
|
Request a Feature
https://www.hackerrank.com/contests/mountblue-technologies/challenges/simple-array-sum 2/2