Check whether each Array element can be reduced to minimum element by replacing it with remainder with some X | Function to check if every integer in the array can be reduced to the minimum array element ; Stores the minimum array element ; Find the minimum element ; Traverse the array arr [ ] ; Stores the maximum value in the range ; Check whether mini lies in the range or not ; Otherwise , return Yes ; Driver code
function isPossible ( arr , n ) { var mini = Number . MAX_VALUE ; for ( var i = 0 ; i < n ; i ++ ) mini = Math . min ( mini , arr [ i ] ) ; for ( var i = 0 ; i < n ; i ++ ) { if ( arr [ i ] == mini ) continue ; var Max = ( arr [ i ] + 1 ) / 2 - 1 ; if ( mini < 0 mini > Max ) return " " ; } return " " ; } var arr = [ 1 , 1 , 3 , 4 ] ; var N = arr . length ; document . write ( isPossible ( arr , N ) ) ;