Distinct Subarrays with At Most K Odd Elements

Given an array A of N integers, determine the total number of distinct subarrays that contain at most K odd elements.

Example:

Input:
A = [3, 2, 3], K = 1
Output:
4
Explanation:

The distinct subarrays with at most 1 odd element are [3], [3,2], [2,3], and [2].

Input:

First line: single integer T (number of test cases)
For each test case:
First line: two space-separated integers N and K
Second line: N space-separated integers representing array A

Output:

For each test case, output the number of distinct subarrays with at most K odd elements.

Constraints:

  • 1 <= T <= 10
  • 1 <= N <= 100
  • 0 <= K <= N
  • 1 <= A[i] <= 109 (for each element A[i])
  • Time Limit: 1 sec

Note:

You are not required to print anything. Just implement the provided function.

Be the first one to answer
Add answer anonymously...
Jio Platforms Graduate Engineer Trainee (Get) Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter