![]() The time complexity of this approach is O(n2), which will be explained later. Use two loops: the outer loop iterates through all of the elements, while the inner loop determines whether or not the current index selected by the outer loop is an equilibrium index. The equilibrium index of this array is 4 because the sum of elements before the index (3+7+1+5 = 16) is equal to the sum of elements after the index (2+7+9 = 18). If there is no equilibrium point, return -1.Ĭonsider an array of integers − Given an array of integers, find the index of the equilibrium point of the array. It is also balanced with another equilibrium index 5 (element 6) because (2+4-3+0-4) = (1). In this sequence, the equilibrium index is 3 (element 0) because (2+4-3) = (-4+6+1). Let's consider the following array − A = We may alternatively state that the array is divided into two parts by the equilibrium index i such that the total of the elements in the left and right sections are equal. Where i is the equilibrium index and arr is the input array. ![]() To put it another way, if we take a look at an array of size n, the equilibrium index i is a point such that − arr + arr +. The position where the sum of the elements to its left and right equals one another is known as the equilibrium index of an array. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |