Check if it is possible to split given Array into K odd | Function to check if array can be split in required K subsets ; Store count of odd numbers ; Check if element is odd ; Check if split is possible ; Driver code
function checkArray ( n , k , arr ) { var cnt = 0 ; for ( i = 0 ; i < n ; i ++ ) { if ( ( arr [ i ] & 1 ) != 0 ) cnt += 1 ; } if ( cnt >= k && cnt % 2 == k % 2 ) return true ; else return false ; } var arr = [ 1 , 3 , 4 , 7 , 5 , 3 , 1 ] ; var n = arr . length ; var k = 4 ; if ( checkArray ( n , k , arr ) ) document . write ( " " ) ; else document . write ( " " ) ;