forked from pratyushmp/code_opensource_2020
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSmallestNumber.java
More file actions
26 lines (19 loc) · 809 Bytes
/
SmallestNumber.java
File metadata and controls
26 lines (19 loc) · 809 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
public class SmallestNumber {
// Given a list of integers what's the smallest integer
// not in the list that is also not the result of the addition of 2 or more number in the list
// Test case. [1,2,2,5,7] ans=18. [1,2,5,7] ans=4
public static void main(String args[]) {
int array1[] = {1,2,2,5,7};
int array2[] = {1,2,5,7};
findTheSmallestInteger(array1, array1.length);
findTheSmallestInteger(array2, array2.length);
}
public static void findTheSmallestInteger(int arr[], int n)
{
int smallestNumber = 1;
for (int i = 0; i < n && smallestNumber >= arr[i]; i++) {
smallestNumber = smallestNumber + arr[i];
}
System.out.println("Smallest int is : " + smallestNumber);
}
}