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.

AnswerBot
4mo
Count the total number of distinct subarrays with at most K odd elements in an array.
Iterate through all subarrays and count the number of odd elements in each subarray.
Use a hashmap to keep track of ...read more
Help your peers!
Add answer anonymously...
Jio Platforms Graduate Engineer Trainee (Get) interview questions & answers
A Graduate Engineer Trainee (Get) was asked 10mo agoQ. Given the head of a singly linked list, return the middle node of the linked lis...read more
A Graduate Engineer Trainee (Get) was asked Q. Explain decorators in Python.
A Graduate Engineer Trainee (Get) was asked Q. Write a query to print the number of employees having a salary of more than 5000...read more
Popular interview questions of Graduate Engineer Trainee (Get)
A Graduate Engineer Trainee (Get) was asked 9mo agoQ1. Given the head of a singly linked list, return the middle node of the linked lis...read more
A Graduate Engineer Trainee (Get) was asked Q2. Explain decorators in Python.
A Graduate Engineer Trainee (Get) was asked Q3. Write a query to print the number of employees having a salary of more than 5000...read more
>
Jio Platforms Graduate Engineer Trainee (Get) Interview Questions
Stay ahead in your career. Get AmbitionBox app


Trusted by over 1.5 Crore job seekers to find their right fit company
80 L+
Reviews
10L+
Interviews
4 Cr+
Salaries
1.5 Cr+
Users
Contribute to help millions
AmbitionBox Awards
Get AmbitionBox app

