Count Stable Segments
Updated
Problem statement
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.
Function
countStableSegments(capacity: int[]) → int
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
Examples
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.
Example 2
capacity = [9, 3, 1, 2, 3, 9, 10]return = 2The 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 interview questions
- Merge Price-Delta FeedsPHONE SCREEN · Seen Dec 2026
- Speed Up a Slow FunctionOA · PHONE SCREEN · Seen Nov 2026
- Portfolio Tickers with Constant-Time Random PickPHONE SCREEN · Seen Nov 2026
- Square Root FunctionPHONE SCREEN · Seen Oct 2026
- Reachable Transfer PositionsPHONE SCREEN · Seen Oct 2026
- Spreadsheet Formula DependenciesPHONE SCREEN · Seen Oct 2026
- Possible MEX Values After One Optional IncrementOA · Seen Oct 2026
- Currency Arbitrage CyclePHONE SCREEN · Seen Sep 2026
- Order Book with Cancel by Order IDPHONE SCREEN · Seen Sep 2026
- Smart Queue of Latest PricesPHONE SCREEN · Seen Sep 2026
Similar questions at other companies
- Count Lamps Lighting Each PointAirbnb · OAAirbnb interview questions
- Maximum Game Score with Fixed Forward JumpsStripe · OAStripe interview questions
- Most Visited Sprint MarkerMicrosoft · OAMicrosoft interview questions
- Split a Matrix Into Four Partitions by Average (Forward Deployed Engineer)Boston Consulting Group · OABoston Consulting Group interview questions
- Earliest Time to Schedule a MeetingMathWorks · OAMathWorks interview questions
- Earliest Meeting Start on a 24-Hour ClockIMC Trading · OAIMC Trading interview questions
- Calculate the Sum After Range TogglesBlink Health · OA
- Optimal TransferSnowflake · OASnowflake interview questions
- Count Attack Vectors by Divisor RangeVisa · OAVisa interview questions
- Smallest Most-Lit Street PositionHudson River Trading · OAHudson River Trading interview questions
Citadel interview experiences
- Citadel Securities Quant Researcher Intern Loop: 1 Experience
- Citadel Securities Research Engineer Interview: 1 Experience
- Citadel Securities SWE Intern First Round: 2 Experiences
- Citadel Securities Experienced SWE Interviews: 1 Experience
- Citadel SWE Intern Later Rounds and Superday: 13 Experiences
- Citadel SWE Intern First-Round Questions: 20 Experiences