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...
Top Graduate Engineer Trainee (Get) Interview Questions Asked at Jio Platforms
Q. Given the head of a singly linked list, return the middle node of the linked lis...read more
Q. Write code for inorder traversal without using recursion.
Q. Explain decorators in Python.
Interview Questions Asked to Graduate Engineer Trainee (Get) at Other Companies
Top Skill-Based Questions for Jio Platforms Graduate Engineer Trainee (Get)
Algorithms Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
SQL Interview Questions and Answers
250 Questions
Java Interview Questions and Answers
250 Questions
Python Interview Questions and Answers
200 Questions
C++ Interview Questions and Answers
150 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

