Check if an array can be split into subarrays with GCD exceeding K | Java program for the above approach ; Function to check if it is possible to split an array into subarrays having GCD at least K ; Iterate over the array arr [ ] ; If the current element is less than or equal to k ; If no array element is found to be less than or equal to k ; Driver code ; Given array arr [ ] ; Length of the array ; Given K ; Function call
import java . io . * ; class GFG { static String canSplitArray ( int arr [ ] , int n , int k ) { for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] <= k ) { return " No " ; } } return " Yes " ; } public static void main ( String [ ] args ) { int arr [ ] = { 2 , 4 , 6 , 1 , 8 , 16 } ; int N = arr . length ; int K = 3 ; System . out . println ( canSplitArray ( arr , N , K ) ) ; } }