Equilibrium Indices in a Sequence

You are given an array/list named 'SEQUENCE', which consists of 'N' integers. The task is to identify all equilibrium indices in this sequence.

Explanation:

An equilibrium index is defined as a position 'i' in the sequence where the sum of elements before 'i' is equal to the sum of elements after 'i'. If no equilibrium index exists, return an empty sequence.

Input:

First line: Integer T (number of test cases) 
For each test case,
First line: Integer N (number of elements in the 'SEQUENCE')
Second line: N space-separated integers (elements of 'SEQUENCE')

Output:

For each test case, output the equilibrium indices as a sequence of integers. If none found, output an empty sequence.

Example:

Input: 
T = 2
N = 4
SEQUENCE = [1, 3, 5, 2]
N = 3
SEQUENCE = [-3, 2, 1]
Output:
[]
[1]

Constraints:

  • 1 <= T <= 50
  • 1 <= N <= 10^4
  • -10^9 <= SEQUENCE[i] <= 10^9
  • Consider the sum of elements below the first index and above the last index as 0.

Note:

The provided function implementation does not require printing the results.

Be the first one to answer
Add answer anonymously...
Accenture Data Engineering Intern 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