FastPrepCount Stable Server Subsegments
Problems/Count Stable Server Subsegments

Count Stable Server Subsegments

Scale AI logoScale AI● MediumNEW GRADOA

Updated Nov 2026

QuestionFunctionExamplesConstraints

Problem statement

Source note: Reported in a Scale AI online assessment. We rebuilt the question. It counts subsegments of length at least three where each of the two end capacities equals the sum of the capacities in between. The example [9,3,3,3,9] returns 2: the middle [3,3,3] and the whole array. Our version is about 98% the same as the reported question.

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[]) → long

Examples

Example 1

capacity = [9,3,1,2,3,9,10]return = 2

The stable subsegments are [9,3,1,2,3,9] and [3,1,2,3].

Example 2

capacity = [3,1,2,3]return = 1

The two endpoints are both 3, and the interior sum is 1+2=3.

Example 3

capacity = [1,1,1]return = 1

The 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

Interview reports that mention this question

  • Scale AI OA: What It Tests (2026)
  • Scale AI New Grad SWE and MLE Question Bank
  • Scale AI New Grad SWE OA Questions: 1 Experience

Scale AI interview experiences

  • Scale AI Forward Deployed Engineer Debugging Round: 1 Experience
  • Scale AI ML Research Engineering Intern Interviews: 1 Experience
  • Scale AI SWE Intern Debugging Interview: 9 Experiences
All Scale AI interview questionsSee Scale AI hiring insights
Saved
class Solution {
    public long countStableServerSegments(long[] capacity) {
        // write your code here
    }
}
Checking account…