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 count of even numbers in a subarray of size K ; Calculate the count of even numbers in the current subarray ; If current element is an even number ; Stores the maximum count of even numbers from all the subarrays of size K ; Traverse remaining subarrays of size K using sliding window technique ; If the first element of the subarray is even ; Update curr ; If i - th element is even increment the count ; Update the answer ; Return answer ; Driver Code ; Size of the input array ; Function call
function maxEvenLetegers ( arr , N , M ) { let curr = 0 ; for ( let i = 0 ; i < M ; i ++ ) { if ( arr [ i ] % 2 == 0 ) curr ++ ; } let ans = curr ; for ( let i = M ; i < N ; i ++ ) { if ( arr [ i - M ] % 2 == 0 ) { curr -- ; } if ( arr [ i ] % 2 == 0 ) curr ++ ; ans = Math . max ( ans , curr ) ; } return ans ; } let arr = [ 2 , 3 , 5 , 4 , 7 , 6 ] ; let M = 3 ; let N = arr . length ; document . write ( maxEvenLetegers ( arr , N , M ) + " " ) ;