Minimum and Maximum element of an array which is divisible by a given number k | Function to find the minimum element ; Function to find the maximum element ; Driver code
function getMin ( arr , n , k ) { let res = Number . MAX_VALUE ; for ( let i = 0 ; i < n ; i ++ ) { if ( arr [ i ] % k == 0 ) res = Math . min ( res , arr [ i ] ) ; } return res ; } function getMax ( arr , n , k ) { let res = Number . MIN_VALUE ; for ( let i = 1 ; i < n ; i ++ ) { if ( arr [ i ] % k == 0 ) res = Math . max ( res , arr [ i ] ) ; } return res ; } let arr = [ 10 , 1230 , 45 , 67 , 1 ] ; let k = 10 ; let n = arr . length ; document . write ( " " + getMin ( arr , n , k ) + " " ) ; document . write ( " " + getMax ( arr , n , k ) ) ;