Skip to content

Commit d05202d

Browse files
committed
--formated: Arrays/AVeryBigSum.java
1 parent 22e3268 commit d05202d

File tree

3 files changed

+27
-14
lines changed

3 files changed

+27
-14
lines changed

Practice Problems/Arrays/A Very Big Sum/AVeryBigSum.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ static long aVeryBigSum(long[] ar) {
77
sum+=i;
88
return sum;
99
}
10+
1011
public static void main(String[]args) {
1112
Scanner sc = new Scanner(System.in);
1213
int a = sc.nextInt();
Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,46 @@
1-
This problem is from Hackerrank.
1+
# A Very Big Sum
2+
3+
**Problem from HackerRank**
4+
25
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.
36

4-
It must return the sum of all array elements.
7+
**Function Description**
58

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.
710

8-
int ar[n]: an array of integers .
11+
`aVeryBigSum` has the following parameter(s):
912

10-
Return
13+
- int ar[n]: an array of integers .
1114

12-
long: the sum of all array elements
15+
**Return** long: the sum of all array elements
1316

14-
Input Format
17+
**Input Format**
1518

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.
1821

19-
Output Format
22+
**Output Format**
2023

2124
Return the integer sum of the elements in the array.
2225

26+
**Constraints**
27+
28+
- 1 <= `n` <= 10
29+
- 0 <= `ar[i]` <= 10<sup>10</sup>
2330

24-
Sample Input
31+
## Example:
2532

33+
**Input**
34+
35+
```java
2636
5
2737
1000000001 1000000002 1000000003 1000000004 1000000005
38+
```
2839

2940
Output
3041

42+
```java
3143
5000000015
44+
```
3245

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.

Practice Problems/Arrays/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ All questions added here are taken from various sites like GeeksForGeeks, LeetCo
44

55
## Problems
66

7+
- [ A Very Big Sum](https://github.com/srsandy/Data-Structures-and-Algorithms-in-Java-2nd-Edition-by-Robert-Lafore/tree/master/Practice%20Problems/Arrays/A%20Very%20Big%20Sum)
78
- [Arrange Students](https://github.com/srsandy/Data-Structures-and-Algorithms-in-Java-2nd-Edition-by-Robert-Lafore/tree/master/Practice%20Problems/Arrays/Arrange%20Students)
89
- [Find All Numbers Disappeared In An Array](https://github.com/srsandy/Data-Structures-and-Algorithms-in-Java-2nd-Edition-by-Robert-Lafore/tree/master/Practice%20Problems/Arrays/Find%20All%20Numbers%20Disappeared%20In%20An%20Array)
910
- [Knight's Possible Moves](https://github.com/srsandy/Data-Structures-and-Algorithms-in-Java-2nd-Edition-by-Robert-Lafore/tree/master/Practice%20Problems/Arrays/Knight's%20Possible%20Moves)

0 commit comments

Comments
 (0)