Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

24/05/2022, 16:15 Simple Array Sum | MountBlue Job Challenge Question | Contests | HackerRank

NEW
PRACTICE CERTIFICATION COMPETE LEADERBOARD  Search   nayanaveeresh101

All Contests

MountBlue Job Challenge

Simple Array Sum

Simple Array Sum

Problem Submissions Leaderboard

Given an array of integers, find the sum of its elements.

For example, if the array , , so return .

Function Description

Complete the simpleArraySum function in the editor below. It must return the sum of the array elements as an integer.

simpleArraySum has the following parameter(s):

ar: an array of integers

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

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

Sample Input

1 2 3 4 10 11

Sample Output

31

Explanation

We print the sum of the array's elements: .

  

Submissions:
5114
Max Score:
10

Rate This Challenge:







More

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

 Upload Code as File


Test against custom input Run Code
Submit Code

Testcase 0 ✓

Congratulations, you passed the sample test case.


Click the Submit Code button to run your code against all the test cases.

Input (stdin)

1 2 3 4 10 11

Your Output (stdout)

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

You might also like