AlgoGenesis is a centralized open-source platform dedicated to providing optimized and well-documented algorithm implementations in C. Perfect for both beginners and advanced users, this repository serves as a comprehensive learning resource for solving algorithmic challenges.
MIT License
88
stars
271
forks
source link
[NEW ALGORITHM] Equilibrium Index in an Array #1438
1) You mention more than one algorithm. You can create a separate issue for each algorithm once the current one is completed.
2) You propose an algorithm that is already present or has been mentioned in a previous issue.
3) You create a new issue without completing your previous issue.
Note: These actions will be taken seriously. Failure to follow the guidelines may result in the immediate closure of your issue.
Name:
[NEW ALGORITHM] Equilibrium Index in an Array
About:
Proposing a new algorithm to find the equilibrium index of an array. The equilibrium index is the position in the array where the sum of elements on the left is equal to the sum of elements on the right.
Detailed Problem Description:
Given an array Arr consisting of N integers, the objective is to find the equilibrium index of the array, where the sum of elements to the left of an index is equal to the sum of elements to the right. If multiple indices satisfy the condition, the left-most index should be returned. If no such index exists, return -1.
Constraints:
1 <= T <= 50 (number of test cases)
1 <= N <= 10^5
-10^4 <= Arr[i] <= 10^4
Time Limit: 1 second
Sample Input:
2 6 1 7 3 6 5 6 4 1 2 3 4
Sample Output:
3 -1
Explanation:
For the first case, the equilibrium index is 3 because the sum of elements to its left is 11 (1 + 7 + 3), and the sum of elements to its right is also 11 (5 + 6).
For the second case, there is no such index, so the output is -1.
Issue will be closed if:
Note: These actions will be taken seriously. Failure to follow the guidelines may result in the immediate closure of your issue.
Name:
[NEW ALGORITHM] Equilibrium Index in an Array
About:
Proposing a new algorithm to find the equilibrium index of an array. The equilibrium index is the position in the array where the sum of elements on the left is equal to the sum of elements on the right.
Detailed Problem Description:
Given an array
Arr
consisting ofN
integers, the objective is to find the equilibrium index of the array, where the sum of elements to the left of an index is equal to the sum of elements to the right. If multiple indices satisfy the condition, the left-most index should be returned. If no such index exists, return -1.Constraints:
1 <= T <= 50
(number of test cases)1 <= N <= 10^5
-10^4 <= Arr[i] <= 10^4
Sample Input: 2 6 1 7 3 6 5 6 4 1 2 3 4
Sample Output: 3 -1
Explanation:
3
because the sum of elements to its left is11
(1 + 7 + 3), and the sum of elements to its right is also11
(5 + 6).-1
.Labels:
new algorithm, gssoc-ext, hacktoberfest, level1
Assignees: