Good Arrays Problem Statement

You are given an array 'A' of length 'N'. You must choose an element from any index in this array and delete it. After deleting the element, you will obtain a new array of length 'N'-1. Your task is to find the number of such arrays of length 'N'-1 that are considered 'good'.

Explanation:

An array is defined as 'good' if the sum of elements at odd indices is equal to the sum of elements at even indices.

Example:

Input:
N = 5
A = [1, 2, 4, 3, 6]
Output:
1
Explanation:

If you delete A[4]=6, the new array B = [1, 2, 4, 3] satisfies the condition: B[0] + B[2] = B[1] + B[3] = 5, thus making it a 'good' array.

Input:

The first line of the input contains 'T' denoting the number of test cases.
The first line of each test case contains an integer 'N', the length of the array.
The second line of each test case contains N space-separated integers of the array A.

Output:

For each test case, print an integer denoting the number of good arrays that can be formed.

Constraints:

  • 1 <= T <= 5
  • 1 <= N <= 3000
  • -5000 <= A[i] <= 5000
  • Time Limit: 1 sec

Note:

You do not need to print anything; it has already been taken care of. Just implement the given function to return the answer.

AnswerBot
4mo

Given an array, find the number of 'good' arrays that can be formed by deleting one element.

  • Iterate through each element in the array and check if deleting it results in a 'good' array

  • Keep track of th...read more

Help your peers!
Select
Add answer anonymously...

Adobe Member Technical Staff interview questions & answers

A Member Technical Staff was asked 10mo agoQ. Given the head of a singly linked list, reverse the list, and return the reverse...read more
A Member Technical Staff was asked Q. How do you find a loop in a Linked List and how do you remove it?
A Member Technical Staff was asked Q. What happens when a recursive function is called?

Popular interview questions of Member Technical Staff

A Member Technical Staff was asked 11mo agoQ1. Given the head of a singly linked list, reverse the list, and return the reverse...read more
A Member Technical Staff was asked Q2. How do you find a loop in a Linked List and how do you remove it?
A Member Technical Staff was asked Q3. What happens when a recursive function is called?
Adobe Member Technical Staff Interview Questions
Stay ahead in your career. Get AmbitionBox app
play-icon
play-icon
qr-code
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

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

Follow Us
  • Youtube
  • Instagram
  • LinkedIn
  • Facebook
  • Twitter
Profile Image
Hello, Guest
AmbitionBox Employee Choice Awards 2025
Winners announced!
awards-icon
Contribute to help millions!
Write a review
Write a review
Share interview
Share interview
Contribute salary
Contribute salary
Add office photos
Add office photos
Add office benefits
Add office benefits