Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

how to find missing number in array

const findMissing = num => {
  const max = Math.max(...num); // Will find highest number
  const min = Math.min(...num); // Will find lowest number
  const missing = []

  for(let i=min; i<= max; i++) {
    if(!num.includes(i)) { // Checking whether i(current value) present in num(argument)
      missing.push(i); // Adding numbers which are not in num(argument) array
    }
  }
  return missing;
}

findMissing([1,10,5,41,35,26,2,15,34,44,12,46,49,50,14, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 27,]);
Source by www.geeksforgeeks.org #
 
PREVIOUS NEXT
Tagged: #find #missing #number #array
ADD COMMENT
Topic
Name
1+7 =