Maximum even numbers present in any subarray of size K | Function to find the maximum count of even numbers from all the subarrays of size K ; Stores the maximum count of even numbers from all the subarrays of size K ; Generate all subarrays of size K ; Store count of even numbers in current subarray of size K ; Traverse the current subarray ; If current element is an even number ; Update the answer ; Return answer ; Driver Code ; Size of the input array
function maxEvenIntegers ( arr , N , M ) { let ans = 0 ; for ( let i = 0 ; i <= N - M ; i ++ ) { let cnt = 0 ; for ( let j = 0 ; j < M ; j ++ ) { if ( arr [ i + j ] % 2 == 0 ) cnt ++ ; } ans = Math . max ( ans , cnt ) ; } return ans ; } let arr = [ 2 , 3 , 5 , 4 , 7 , 6 ] ; let K = 3 ; let N = arr . length ; document . write ( maxEvenIntegers ( arr , N , K ) + " " ) ;