Dsa
Sliding Window
Easy
Count Subarrays with at Most K Even Numbers
You are given an array of integers and an integer k. Write a function that counts the number of contiguous subarrays that contain at most k even numbers. The input consists of two lines: the first line contains the integer k, and the second line contains a list of integers. Return the count as an integer.
Example:
Input:
2
1 2 3 4 5 6 7 8
Output:
16
Key concepts
sliding_windowcountingarray
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now