help understanding how to interpret a function

I was asked to write a function :
int solution(const vector<int> &A)that, given a zero-indexed array A consisting of N integers, returns any of its equilibrium indices.
Can someone please help me interpret what this means and help me brainstorm for a solution?
Are there more parameters?
Where does N come from?

zero-indexed array, maybe just array that have the first element at index 0.


I read it wrong, my bad eng lol. Thought you gonna generate new array.
Last edited on
For example: the array A containing 5 elements where:
A[0] = 1
A[1] = 4
A[2] = -1
A[3] = 3
A[4] = 2

The function will return the value 4:
A[0]:= 1 ==> A[1] :=4 ==> A[4] := 2 ==> A[2] := -1
1 2 3 4

= 4 elements total in the list.


Also, I am writing the program in C++
Last edited on
1
2
3
4
5
A[0] = 1
A[1] = 4
A[2] = -1
A[3] = 3
A[4] = 2


The function will return the value 4:
A[0]:= 1 ==> A[1] :=4 ==> A[4] := 2 ==> A[2] := -1
1 2 3 4

= 4 elements total in the list.


There are no equilibrium indexes for the array you've listed here. Is this an example given in your instructions?

I too sent the wrong example.

Here is the example: array A consisting of N = 8 elements:
A[0] = -1
A[1] = 3
A[2] = -4
A[3] = 5
A[4] = 1
A[5] = -6
A[6] = 2
A[7] = 1

I know the equilibrium index is 1,3 or 7. The function should return any of the equilibrium indices. If no equilibrium exists, it will return -1.
Topic archived. No new replies allowed.