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.
AnswerBot
1y
The task is to find the equilibrium indices of a given sequence, where the sum of elements at lower indices is equal to the sum of elements at higher indices.
Iterate through the sequence and calculate...read more
Help your peers!
Add answer anonymously...
Top Springworks Software Developer interview questions & answers
Popular interview questions of Software Developer
Top HR questions asked in Springworks Software Developer
Stay ahead in your career. Get AmbitionBox app
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
Get AmbitionBox app