Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@thmain
Last active May 29, 2018 01:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thmain/91fe10ba17aa40a84143 to your computer and use it in GitHub Desktop.
Save thmain/91fe10ba17aa40a84143 to your computer and use it in GitHub Desktop.
public class SmallestIntegerInSortedArray {
public int find(int [] arrA){
int smlNumber = 1;
for(int i = 0;i<arrA.length;i++){
if(arrA[i]<=smlNumber){
smlNumber += arrA[i];
}else{
break;
}
}
return smlNumber;
}
public static void main(String arg[]){
SmallestIntegerInSortedArray i = new SmallestIntegerInSortedArray();
System.out.println("Smallest Positive Integer that cant be represented by the sum of any subset of following arrays are : ");
int [] arrA = { 1,1,3,4,6,7,9};
System.out.println("{1,1,3,4,6,7,9} -" + i.find(arrA));
int [] arrB = {1,1,1,1,1};
System.out.println("{1,1,1,1,1} -" + i.find(arrB));
int [] arrC = {2,3,6,7};
System.out.println("{2,3,6,7} -" + i.find(arrC));
int [] arrD = {1,2,6,7,9};
System.out.println("{1,2,6,7,9} -"+ i.find(arrD));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment