Finding Equilibrium Index in Java Array

Day 25: Finding the Equilibrium Index of an Array using Java An equilibrium index of an array is the index where the sum of elements on the left side is equal to the sum of elements on the right side. To solve this problem efficiently, I followed a simple approach: 🔹 First, I calculated the total sum of the array elements. 🔹 Then while iterating through the array, I maintained a left_sum variable. 🔹 The right_sum can be calculated using the formula: right_sum = total_sum - arr[i] - left_sum 🔹 If at any index left_sum equals right_sum, that index becomes the equilibrium index. 📌 Example: Array: [-7, 5, 1, 5, -4, 3, 0] Equilibrium Index: 3 At index 3: Left Sum = -7 + 5 + 1 = -1 Right Sum = -4 + 3 + 0 = -1 Both sums are equal, so index 3 is the equilibrium index. Problems like these are a great way to strengthen array manipulation and algorithmic thinking in Java. #Java #ProblemSolving #CodingPractice #DataStructures #Arrays #Programming Raviteja T Mohammed Abdul Rahman 10000 Coders

  • graphical user interface, text, application, email

To view or add a comment, sign in

Explore content categories