Count Stable Segments
In an organization, there are n servers, each with a capacity of capacity[i]. A contiguous subsegment[l, r] of servers is said to be stable if capacity[i] = capacity[r] = sum[l + 1, r - 1]. In other words, the capacity of the servers at the endpoints of the segment should be equal to the sum the sum of the capacities of all the interior servers.
Find the num of stable sub-segments of length 3 or more.
Complete the function countStableSegments in the editor.
countStableSegments has the following parameters:
int[] capacity: the capacity of each server
Returns
int: the num of stable segments
ʚଓ Many thanks to Aura Man𓂃 𓈒𓏸
1Example 1

2Example 2
Constraints
Limits and guarantees your solution can rely on.
1 ≤ n ≤ 10^51 <= capacity[i] <= 10^5