Jul 23, 2014 at 1:00am UTC
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?
Jul 23, 2014 at 1:47am UTC
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 Jul 23, 2014 at 2:21am UTC
Jul 23, 2014 at 2:15am UTC
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 Jul 23, 2014 at 3:21am UTC
Jul 23, 2014 at 3:27am UTC
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.