DEV Community

Cover image for hackerrank algorithms solution
Noah Mugaya
Noah Mugaya

Posted on

4 3

hackerrank algorithms solution

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

if the array, arr = [1, 2, 3], 1+2+3 so return 6

function discription

_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,n , denoting the size of the array.
The second line contains space-separated integers representing the array's element
_

solutions

// bin/python3
import math
import os
import random
import re
import sys

we define a function to return an interger

def simpleArraySum(ar):
# Write your code here
x=0
for i in range(0,ar_count):
x += ar[i]
return x
if name == 'main':
fptr = open(os.environ['OUTPUT_PATH'], 'w')

ar_count = int(input().strip())

ar = list(map(int, input().rstrip().split()))

result = simpleArraySum(ar)

fptr.write(str(result) + '\n')

fptr.close()
Enter fullscreen mode Exit fullscreen mode

Enter fullscreen mode Exit fullscreen mode

Image of Datadog

The Future of AI, LLMs, and Observability on Google Cloud

Datadog sat down with Google’s Director of AI to discuss the current and future states of AI, ML, and LLMs on Google Cloud. Discover 7 key insights for technical leaders, covering everything from upskilling teams to observability best practices

Learn More

Top comments (0)

Sentry image

See why 4M developers consider Sentry, “not bad.”

Fixing code doesn’t have to be the worst part of your day. Learn how Sentry can help.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay