Given an array of integers loads of length N, a server at index i is balanced if the sum of elements to its left equals the sum of elements to its right. After removing exactly one element at index j (where j != i), the remaining N-1 elements form a new sequence. A server originally at index i (now at a new position i') is considered balanced in the new configuration if the sum of elements at indices 0 to i'-1 equals the sum of elements at indices i'+1 to N-2. Return the total count of unique pairs (i, j) where i != j such that the server originally at index i is balanced in the new configuration.
Explanation: If we remove index 0, array is [2, 3]. No middle element exists to be balanced. If we remove index 1, array is [1, 3]. No. If we remove index 2, array is [1, 2]. No.
Explanation: If we remove index 3 (value 2), the array becomes [1, 2, 1]. The element at original index 1 (now index 1) has left sum (1) and right sum (1). This is a valid pair (1, 3).
Master coding challenges related to Arrays and solve the Data Center Load Balancing problem optimally.
No dry run loaded.
🚀 Practice this problem
Run code, get AI hints & track streak