Skip to content
Programmingoneonone
Programmingoneonone

Learn everything about programming

  • Home
  • CS Subjects
    • Internet of Things (IoT)
    • Digital Communication
    • Human Values
    • Cybersecurity
  • Programming Tutorials
    • C Programming
    • Data structures and Algorithms
    • 100+ Java Programs
    • 100+ C Programs
  • HackerRank Solutions
    • HackerRank Algorithms Solutions
    • HackerRank C problems solutions
    • HackerRank C++ problems solutions
    • HackerRank Java problems solutions
    • HackerRank Python problems solutions
Programmingoneonone
Programmingoneonone

Learn everything about programming

HackerRank Simple Array Sum problem solution

YASH PAL, 31 July 202430 November 2025

In this HackerRank Simple Array Sum problem solution, Given an array of integers, find the sum of its elements.

For example, if the array ar = [1,2,3],1+2+3 = 6, so return 6.

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, n, denoting the size of the array.

The second line contains n space-separated integers representing the array’s elements.

Constraints

0 < n, ar[i] <= 1000

Output Format

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

Hackerrank simple array sum solution
simple array sum solution

HackerRank Simple Array sum problem solution in Python.

#!/bin/python3

import os
import sys

#
# Complete the simpleArraySum function below.
#
def simpleArraySum(ar):
    x=0
    for i in range(0,ar_count):
        x = x + ar[i]
    return x


if __name__ == '__main__':
    fptr = open(os.environ['OUTPUT_PATH'], 'w')

    ar_count = int(input())

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

    result = simpleArraySum(ar)

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

    fptr.close()

Simple Array Sum solution in Java.

import java.io.*;
import java.util.*;

public class Solution {

	public static void main(String[] args) throws Exception
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		br.readLine();
		int output=0;
		String[] input = br.readLine().split(" ");
		for(String value:input)
		{
			output += Integer.parseInt(value);
		}
		System.out.println(output);
	}
}

Simple Array sum solution in C++.

#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;


int main() {
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */   
    int numLines;
    int currNumber, total = 0;
    
    cin >> numLines;
    
    for (int i=0; i<numLines;i++) {
        cin >> currNumber;
        total += currNumber;
    }
    
    cout << total;
    
    return 0;
}

Simple Array sum solution in C.

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
int N;
int map[1000];
int main() {
  long int sum =0;
    scanf("%d",&N);
    for(int i = 0; i<N; i++)
        {
      scanf("%d",&map[i]);
    }
    for(int i=0; i<N;i++)
        {
        sum += map[i];
    }
    /* Enter your code here. Read input from STDIN. Print output to STDOUT */    
    printf("%ld",sum);
    return 0;
}

Simple Array Sum solution in JavaScript.

function processData(input) {
    console.log(input.split(/n/)[1].split(/s/).map(Number).reduce(function(a, b) {
        return a + b;
    }))
} 

process.stdin.resume();
process.stdin.setEncoding("ascii");
_input = "";
process.stdin.on("data", function (input) {
    _input += input;
});

process.stdin.on("end", function () {
   processData(_input);
});

Other problem solutions

  • HackerRank Compare the triplets problem solution
  • HackerRank A very big sum problem solution
  • HackerRank Diagonal difference problem solution
  • HackerRank Plus minus problem solution
  • HackerRank Mini-Max sum problem solution
Algorithms coding problems solutions AlgorithmsHackerRank

Post navigation

Previous post
Next post

Leave a Reply

Your email address will not be published. Required fields are marked *

Are you a student and stuck with your career or worried about real-time things, and don't know how to manage your learning phase? Which profession to choose? and how to learn new things according to your goal, and land a dream job. Then this might help to you.

Hi My name is YASH PAL, founder of this Blog and a Senior Software engineer with 5+ years of Industry experience. I personally helped 40+ students to make a clear goal in their professional lives. Just book a one-on-one personal call with me for 30 minutes for 300 Rupees. Ask all your doubts and questions related to your career to set a clear roadmap for your professional life.

Book session - https://wa.me/qr/JQ2LAS7AASE2M1

Pages

  • About US
  • Contact US
  • Privacy Policy

Follow US

  • YouTube
  • LinkedIn
  • Facebook
  • Pinterest
  • Instagram
©2025 Programmingoneonone | WordPress Theme by SuperbThemes