Check whether each Array element can be reduced to minimum element by replacing it with remainder with some X | Java program for the above approach ; 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
import java . io . * ; import java . util . * ; class GFG { static String isPossible ( int arr [ ] , int n ) { int mini = Integer . MAX_VALUE ; for ( int i = 0 ; i < n ; i ++ ) mini = Math . min ( mini , arr [ i ] ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] == mini ) continue ; int Max = ( arr [ i ] + 1 ) / 2 - 1 ; if ( mini < 0 mini > Max ) return " No " ; } return " Yes " ; } public static void main ( String args [ ] ) { int arr [ ] = { 1 , 1 , 3 , 4 } ; int N = arr . length ; System . out . print ( isPossible ( arr , N ) ) ; } }