|
1 | | -This problem is from Hackerrank. |
| 1 | +# A Very Big Sum |
| 2 | + |
| 3 | +**Problem from HackerRank** |
| 4 | + |
2 | 5 | 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.
|
3 | 6 |
|
4 | | -It must return the sum of all array elements. |
| 7 | +**Function Description** |
5 | 8 |
|
6 | | -aVeryBigSum has the following parameter(s): |
| 9 | +Complete the `aVeryBigSum` function in the editor below. It must return the sum of all array elements. |
7 | 10 |
|
8 | | -int ar[n]: an array of integers . |
| 11 | +`aVeryBigSum` has the following parameter(s): |
9 | 12 |
|
10 | | -Return |
| 13 | +- int ar[n]: an array of integers . |
11 | 14 |
|
12 | | -long: the sum of all array elements |
| 15 | +**Return**long: the sum of all array elements |
13 | 16 |
|
14 | | -Input Format |
| 17 | +**Input Format** |
15 | 18 |
|
16 | | -The first line of the input consists of an integer . |
17 | | -The next line contains space-separated integers contained in the array. |
| 19 | +The first line of the input consists of an integer `n`. |
| 20 | +The next line contains `n` space-separated integers contained in the array. |
18 | 21 |
|
19 | | -Output Format |
| 22 | +**Output Format** |
20 | 23 |
|
21 | 24 | Return the integer sum of the elements in the array.
|
22 | 25 |
|
| 26 | +**Constraints** |
| 27 | + |
| 28 | +- 1 <= `n` <= 10 |
| 29 | +- 0 <= `ar[i]` <= 10<sup>10</sup> |
23 | 30 |
|
24 | | -Sample Input |
| 31 | +## Example: |
25 | 32 |
|
| 33 | +**Input** |
| 34 | + |
| 35 | +```java |
26 | 36 | 5
|
27 | 37 | 1000000001 1000000002 1000000003 1000000004 1000000005
|
| 38 | +``` |
28 | 39 |
|
29 | 40 | Output
|
30 | 41 |
|
| 42 | +```java |
31 | 43 | 5000000015
|
| 44 | +``` |
32 | 45 |
|
33 | | -Note: |
34 | | - |
35 | | -When we add several integer values, the resulting sum might exceed the above range. You might need to use long int C/C++/Java to store such sums. |
| 46 | +**Note:** The range of the 32 bit integer is (-2<sup>31</sup>) to (2<sup>31</sup> - 1) or [-2147483648, 2147483648]. When we add several integer values, the resulting sum might exceed the above range. You might need to use long int C/C++/Java to store such sums. |
0 commit comments