
Asked in Amdocs
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...
Top Associate Software Engineer Interview Questions Asked at Amdocs
Q. How do you solve technical problems using recursion?
Q. Write an SQL query to fetch records and use a join to group three tables.
Q. What is the Collection Framework in Java?
Interview Questions Asked to Associate Software Engineer at Other Companies
Top Skill-Based Questions for Amdocs Associate Software Engineer
Data Structures Interview Questions and Answers
250 Questions
Algorithms Interview Questions and Answers
250 Questions
Java Interview Questions and Answers
250 Questions
SQL Interview Questions and Answers
250 Questions
Web Development Interview Questions and Answers
250 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

