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 M ; Stores the count of even numbers in a subarray of size M ; 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 M ; Traverse remaining subarrays of size M 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
def maxEvenIntegers ( arr , N , M ) : NEW_LINE INDENT curr = 0 NEW_LINE for i in range ( 0 , M ) : NEW_LINE INDENT if ( arr [ i ] % 2 == 0 ) : NEW_LINE INDENT curr += 1 NEW_LINE DEDENT DEDENT ans = curr NEW_LINE for i in range ( M , N ) : NEW_LINE INDENT if ( arr [ i - M ] % 2 == 0 ) : NEW_LINE INDENT curr -= 1 NEW_LINE DEDENT if ( arr [ i ] % 2 == 0 ) : NEW_LINE INDENT curr += 1 NEW_LINE ans = max ( curr , ans ) NEW_LINE DEDENT DEDENT return ans NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 2 , 3 , 5 , 4 , 7 , 6 ] NEW_LINE M = 3 NEW_LINE N = len ( arr ) NEW_LINE print ( maxEvenIntegers ( arr , N , M ) ) NEW_LINE DEDENT