Problem · Array
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𓂃 𓈒𓏸
Examples
01 · Example 1
capacity = [9, 3, 3, 3, 9] return = 2

There are 2 stable subsegments: [3, 3, 3] and [9, 3, 3, 3, 9]. Return 2.
02 · Example 2
capacity = [9, 3, 1, 2, 3, 9, 10] return = 2
The stable segments are [9, 3, 1, 2, 3, 9] and [3, 1, 2, 3] :D
Constraints
1 ≤ n ≤ 10^51 <= capacity[i] <= 10^5
More Citadel problems
- Minimum Path Sum to Target in Binary TreePHONE SCREEN · Seen Apr 2026
- Social Media SuggestionsSeen May 2025
- Best Sum Downward Tree PathSeen May 2025
- Price CheckSeen Feb 2025
- Palindromic Substrings (LC 647 :)Seen Jan 2025
- Get Distinct Goodness ValuesSeen Jan 2025
- Get Min OperationsSeen Jan 2025
- Find Consistent LogsSeen Oct 2024
public int countStableSegments(int[] capacity) {
// write your code here
}
capacity[9, 3, 3, 3, 9]
expected2
sign in to submit