Smallest positive integer that does not divide any elements of the given array | Function to find the smallest number which doesn 't divides any integer in the given array arr[] ; Traverse the array arr [ ] ; Maximum array element ; Initialize variable ; Traverse from 2 to max ; Stores if any such integer is found or not ; If any array element is divisible by j ; Smallest integer ; Print the answer ; Driver Code ; Function Call
function smallestNumber ( arr , len ) { let maxi = 0 ; for ( let i = 0 ; i < len ; i ++ ) { maxi = Math . max ( maxi , arr [ i ] ) ; } let ans = - 1 ; for ( let i = 2 ; i < maxi + 2 ; i ++ ) { let flag = true ; for ( let j = 0 ; j < len ; j ++ ) { if ( arr [ j ] % i == 0 ) { flag = false ; break ; } } if ( flag ) { ans = i ; break ; } } document . write ( ans ) ; } let arr = [ 3 , 2 , 6 , 9 , 2 ] ; let N = arr . length ; smallestNumber ( arr , N ) ;