this question has answer here:
i struggling logic behind solving following prompt: unsorted integer array contains 98 different numbers 1 100. so, among numbers 1 100, 2 distinct numbers missing. find them.
i understand concept behind finding 1 missing number, second 1 that's giving me issues. suggestions?
yes, have seen entry, found answers given either complex , detailed or off topic. java beginner - trying wrap head around this.
edit: @ following initiating array numbers 1-100 , sorting them:
for (int = 0; < arr.length; i++) { int j = + 1; if (arr[j] - arr[i] > 1){ int missing = arr[i + 1]; system.out.println(missing); } }
my issue cannot loop print actual missing number. prints number above missing number. have tried few different ways , either prints number above or below, never actual missing number.
sort array , loop , if next element in loop not previous+1 missing one. save previous value separate variable more distincts numbers 1 after another.
Comments
Post a Comment