Last active
May 29, 2018 01:07
-
-
Save thmain/91fe10ba17aa40a84143 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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