Find if it is possible to choose subarray that it contains exactly K even integers | Function to check if it is possible to choose a subarray that contains exactly K even integers ; Variable to store the count of even numbers ; If we have to select 0 even numbers but there is all odd numbers in the array ; If the count of even numbers is greater than or equal to K then we can select a subarray with exactly K even integers ; If the count of even numbers is less than K then we cannot select any subarray with exactly K even integers ; Driver code
function isPossible ( A , n , k ) { var countOfTwo = 0 ; for ( var i = 0 ; i < n ; i ++ ) { if ( A [ i ] % 2 == 0 ) { countOfTwo ++ ; } } if ( k == 0 && countOfTwo == n ) document . write ( " " ) ; else if ( countOfTwo >= k ) { document . write ( " " ) ; } else document . write ( " " ) ; } var arr = [ 1 , 2 , 4 , 5 ] ; var K = 2 ; var N = arr . length ; isPossible ( arr , N , K ) ;