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.

Be the first one to answer
Add answer anonymously...
Amdocs Software Engineer Interview Questions
Stay ahead in your career. Get AmbitionBox app
qr-code
Helping over 1 Crore job seekers every month in choosing their right fit company
65 L+

Reviews

4 L+

Interviews

4 Cr+

Salaries

1 Cr+

Users/Month

Contribute to help millions

Made with ❤️ in India. Trademarks belong to their respective owners. All rights reserved © 2024 Info Edge (India) Ltd.

Follow us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter