-
[HackerRank] A Very Bing Sum c++Coding Test/HackerRank 2022. 7. 16. 20:32728x90
- Problem
In this challenge, you are required to calculate and print the sum of the elements in an array, keeping in mind that some of those integers may be quite large.
- Function Description
Complete the aVeryBigSum function in the editor below. It must return the sum of all array elements.
aVeryBigSum has the following parameter(s):
- int ar[n]: an array of integers .
- sample input
5 1000000001 1000000002 1000000003 1000000004 1000000005
- output
5000000015
- solution (c++)
long aVeryBigSum(vector<long> ar) { unsigned long int sum = 0; for(auto &it : ar){ sum += it; } return sum; }
- solution (python)
def aVeryBigSum(ar): # Write your code here ans = 0 for num in ar: ans += int(num) return ans
파이썬...자료형 신경안써도 되고 새삼 감탄
728x90'Coding Test > HackerRank' 카테고리의 다른 글
[HackerRank] Birthday Cake Candles c++ (0) 2022.07.18 [HackerRank] Mini-Max Sum c++ (0) 2022.07.16 [HackerRank] Staircase c++ (0) 2022.07.16 [HackerRank] Plus Minus c++ (0) 2022.07.16 [HackerRank] Diagonal Difference c++ (0) 2022.07.16