Subarray with Equal Occurrences Problem Statement
You are provided with an array/list ARR
of length N
containing only 0s and 1s. Your goal is to determine the number of non-empty subarrays where the number of 0s is equal to the number of 1s.
Input:
The first line contains an integer 'T' indicating the number of test cases. Each test case consists of:
- The first line contains a positive integer 'N', the length of the array/list.
- The second line contains 'N' space-separated integers representing the elements of the array/list.
Output:
For each test case, output a single line with the count of subarrays in which the number of 0s and 1s are equal. Provide the output for each test case on a new line.
Example:
Input:
2
4
0 1 0 1
5
1 0 0 1 1
Output:
4
2
Constraints:
1 <= T <= 100
1 <= N <= 5 * 10^3
0 <= ARR[i] <= 1
- Time limit: 1 sec
Note:
There is no need to print the expected output; it is handled automatically. Focus on implementing the solution function.

AnswerBot
4mo
Count the number of subarrays where the number of 0s is equal to the number of 1s in a given array of 0s and 1s.
Iterate through the array and keep track of the count of 0s and 1s encountered so far.
Us...read more
Help your peers!
Add answer anonymously...
Amdocs Associate Software Engineer interview questions & answers
An Associate Software Engineer was asked 2mo agoQ. Write an SQL query to fetch records and use a join to group three tables.
An Associate Software Engineer was asked 2mo agoQ. How do you solve technical problems using recursion?
An Associate Software Engineer was asked 9mo agoQ. What is the Collection Framework in Java?
Popular interview questions of Associate Software Engineer
An Associate Software Engineer was asked 2mo agoQ1. Write an SQL query to fetch records and use a join to group three tables.
An Associate Software Engineer was asked 2mo agoQ2. How do you solve technical problems using recursion?
An Associate Software Engineer was asked 9mo agoQ3. What is the Collection Framework in Java?
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

