
Asked in Amdocs
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...
Top Software Engineer Interview Questions Asked at Amdocs
Q. What do you know about relational databases?
Q. What is the difference between arrays and ArrayLists in Java?
Q. Given a circular cake and a specified number of straight cuts, what is the maxim...read more
Interview Questions Asked to Software Engineer at Other Companies
Top Skill-Based Questions for Amdocs Software Engineer
Algorithms Interview Questions and Answers
250 Questions
Data Structures Interview Questions and Answers
250 Questions
Web Development Interview Questions and Answers
250 Questions
Java Interview Questions and Answers
250 Questions
Software Development Interview Questions and Answers
250 Questions
SQL Interview Questions and Answers
250 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

