Subarray with Equal Occurrences Problem Statement
Given an array ARR
consisting of 0s and 1s only, your task is to determine the number of non-empty subarrays where the number of 0s and 1s are equal.
Input:
The first line contains an integer 'T' representing the number of test cases. Each test case contains: - The first line with a positive integer 'N', the length of the array/list. - The second line with 'N' space-separated integers, each being either 0 or 1, representing the array/list.
Output:
For each test case, output the count of subarrays where the number of 0s and 1s are equal. Each test case's result should be printed on a new line.
Example:
Input:
2
6
0 1 0 1 0 1
4
1 0 1 0
Output:
9
4
Constraints:
- 1 <= T <= 100
- 1 <= N <= 5 * 103
- 0 <= ARR[i] <= 1
Note the time limit is 1 second.

AnswerBot
4mo
Count the number of subarrays where the number of 0s and 1s are equal 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.
Use a hashmap ...read more
Help your peers!
Add answer anonymously...
Amdocs Software Engineer interview questions & answers
A Software Engineer was asked 4d agoQ. What do you know about relational databases?
A Software Engineer was asked 4mo agoQ. Write a JUnit test case.
A Software Engineer was asked 6mo agoQ. What is the difference between arrays and ArrayLists in Java?
Popular interview questions of Software Engineer
A Software Engineer was asked 5d agoQ1. What do you know about relational databases?
A Software Engineer was asked 4mo agoQ2. Write a JUnit test case.
A Software Engineer was asked 6mo agoQ3. What is the difference between arrays and ArrayLists 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

