Check if an array can be split into subarrays with GCD exceeding K | C ++ 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
#include <iostream> NEW_LINE using namespace std ; string canSplitArray ( int arr [ ] , int n , int k ) { for ( int i = 0 ; i < n ; i ++ ) { if ( arr [ i ] <= k ) { return " No " ; } } return " Yes " ; } int main ( ) { int arr [ ] = { 2 , 4 , 6 , 1 , 8 , 16 } ; int N = sizeof arr / sizeof arr [ 0 ] ; int N = sizeof arr / sizeof arr [ 0 ] ; int K = 3 ; cout << canSplitArray ( arr , N , K ) ; }