Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Equilibrium index

807597Oct 26 2005 — edited Oct 26 2005
Any help please ?

Equilibrium index

Equilibrium index of a sequence is an index such that the sum of elements at lower indexes is equal to the sum of elements at higher indexes. For example, in a sequence A:



A[0]=-7 A[1]=1 A[2]=5 A[3]=2 A[4]=-4 A[5]=3 A[6]=0

3 is an equilibrium index, because : :

A[0] + A[1] + A[2] = A[4] + A[5] + A[6]

6 is also an equilibrium index, because:

A[0] + A[1] + A[2] + A[3] + A[4] + A[5] = 0 (sum of zero elements is zero)


7 is not an equilibrium index, because it is not a valid index of sequence A.



If you still have doubts, this is a precise definition: the integer k is an equilibrium index of a sequence A[0],A[1],...,A[n] if and only if 0≤k≤ n and . We assume that sum of zero elements is equal zero.



Write a function, that given a sequence, returns its equilibrium index (any) or -1 if no equilibrium indexes exist. Assume that the sequence may be very long. If possible, use one of the following languages and define your function as follows:


Java static public int equi(int a[]) // in class Equi
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Nov 23 2005
Added on Oct 26 2005
36 comments
540 views