5/3/2023 0 Comments Javascript for each index![]() Example 3:Įxplanation: There is no such equilibrium index in the array. Input: A =, Output: 1Įxplanation: 1 is an equilibrium index, i.e., A = A + A + A = 0. Input: A =, Output: 3Įxplanation: 3 is an equilibrium index, i.e., A + A + A = A + A + A = -1. For i = n - 1, we assume that the sum of elements at higher indexes is equal to 0.For i = 0, we assume that the sum of elements at lower indexes is equal to 0.In other words, the equilibrium index of an array is an index i such that the sum of elements at indices less than i is equal to the sum of elements at indices greater than i. A + A + …. The equilibrium index of an array is an index such that the sum of elements at lower indexes is equal to the sum of elements at higher indexes. Write a program to find the equilibrium index of an array. Key takeaway: This problem is an excellent opportunity to learn problem-solving and step-by-step optimization using loops and variables. Difficulty: Easy | Asked-in: Amazon, Adobe, Hike
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |