We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
  • Hackerrank Home
  • Prepare
    NEW
  • Certify
  • Compete
  • Career Fair
  • Hiring developers?
  1. Prepare
  2. Algorithms
  3. Warmup
  4. Simple Array Sum
  5. Discussions

Simple Array Sum

Problem
Submissions
Leaderboard
Discussions
Editorial

Sort 3088 Discussions, By:

recency

Please Login in order to post a comment

  • nihal_navale22
    13 hours ago+ 0 comments

    ** C ++ **

    int simpleArraySum(vector<int> ar) {
    int sum = 0;
    for (int i=0; i<ar.size(); i++){
        sum = sum + ar.at(i);
    }
    return sum;
    }
    
    0|
    Permalink
  • daht_x
    13 hours ago+ 0 comments

    Simple array sum | C#

    Common

    internal interface ISolution
    {
        int SimpleArraySum(List<int> integers);
    }
    

    Solution one

    internal sealed class SolutionOne : ISolution
    {
        public int SimpleArraySum(List<int> integers)
        {
            int sum = default;
            foreach (int integer in integers)
            _ = sum += integer;
            return sum;
        }
    }
    

    Solution two

    internal sealed class SolutionTwo : ISolution
    {
        public int SimpleArraySum(List<int> integers)
            => integers.Sum();
    }
    

    Solution three

    internal sealed class SolutionThree : ISolution
    {
        public int SimpleArraySum(List<int> integers)
            => integers.Aggregate(0, static (total, next) => total + next);
    }
    
    0|
    Permalink
  • premascii
    17 hours ago+ 0 comments

    for java , we are getting input as list type array so our code will be a bit different than the simple array, code will be like this if you find any correction please let me know too.

    public static int simpleArraySum(List<Integer> ar) {
        int sum = 0;
        for(int i=0; i<ar.size();i++)
             {
                sum+=ar.get(i);
             }
            return sum;
        }
    
    0|
    Permalink
  • jhonsonrob32
    1 week ago+ 0 comments

    Bundle of thansk for sharing this. I am going to implement it on my webiste that is related to cleaning a septic tank.

    -2|
    Permalink
  • Kristina_1191511
    1 week ago+ 0 comments

    Very simple C++ code.

    #include <iostream>
    
    using namespace std;
    
    int main()
    { 
    int n,i; 
    cin>>n; //limit of the array.
    int ar[n];
    int sum = 0;
    for(i=0; i<n; i++){
        cin>>ar[i];
    }
    
    for(i=0; i<n; i++){
        sum= sum+ar[i];
    }
    
    cout<<sum;
    
        return 0;
    }
    
    -3|
    Permalink
Load more conversations

Need Help?


View editorial
View top submissions
  • Blog
  • Scoring
  • Environment
  • FAQ
  • About Us
  • Support
  • Careers
  • Terms Of Service
  • Privacy Policy