Count Stable Server Subsegments
Updated
Problem statement
You are given an array capacity of positive server capacities.
A contiguous subsegment [l,r] is stable when it has length at least three and both endpoint capacities equal the sum of all interior capacities:
capacity[l] = capacity[r] = capacity[l+1] + ... + capacity[r-1].
Return the number of stable subsegments.
Function
countStableServerSegments(capacity: long[]) → longExamples
Example 1
capacity = [9,3,1,2,3,9,10]return = 2The stable subsegments are [9,3,1,2,3,9] and [3,1,2,3].
Example 2
capacity = [3,1,2,3]return = 1The two endpoints are both 3, and the interior sum is 1+2=3.
Example 3
capacity = [1,1,1]return = 1The only length-three subsegment satisfies 1=1=1.
Constraints
1 <= capacity.length <= 300000.1 <= capacity[i] <= 1000000000.- The answer fits in a signed 64-bit integer.
More Scale AI Online Assessment questions
- Part 2: Batch Access ReviewOA · Seen Nov 2026
- Part 1: The Narrowest KeyOA · Seen Nov 2026
- Build Sessions from Unordered Events (Part 1)OA · Seen Oct 2026
- Match Billing Charges to User Sessions (Part 2)OA · Seen Oct 2026
- Four-Player Trick-Taking Card Game SimulationOA · PHONE SCREEN · Seen Aug 2026
- Free Windows Between Busy IntervalsOA · PHONE SCREEN · Seen Apr 2026
- Compare Labeling Worker AnnotationsOA · Seen Mar 2025
- Distinct OR Values of Increasing SubsequencesOA · Seen Nov 2024
- Running Through Walls with Limited EnergyOA · Seen Sep 2024
- Relative Score Graph ComponentsOA · Seen Sep 2023
Similar questions at other companies
- Count Subarrays with a Perfect-Square ProductMicrosoft · OAMicrosoft interview questions
- Count Zero-Sum FragmentsTesla · OATesla interview questions
- Number of Unique Elements After Modifications 🍁Infosys · OAInfosys interview questions
- Count Paired Subarrays Reaching a TargetZipRecruiter · OAZipRecruiter interview questions
- Count Subarrays with Sum KIndeed · OAIndeed interview questions
- Count Subarrays With Given XORInMobi · OAInMobi interview questions
- Count Subarrays with Sum Divisible by KVisa · OAVisa interview questions
- Beautiful SubarraysAtlassian · OAAtlassian interview questions
- Find Security LevelAmazon · OA
- Subarray Sum Equals KServiceNow · ONSITE INTERVIEWServiceNow interview questions