Three-Part Splits With a Light Middle
Updated
Problem statement
You are given an array values of n integers. Cut it in two places so it becomes three parts in a row: a left part, a middle part and a right part. Each part must hold at least one number, and the numbers keep their order.
Let S1, S2 and S3 be the sums of the left, middle and right parts. A split has a light middle when S2 <= S1 + S3. Equal sums count.
- Numbers can be negative or zero.
- Two splits are different when at least one cut is in a different place.
Return the number of splits with a light middle.
Function
countLightMiddleSplits(values: int[]) → intExamples
Example 1
values = [2,5,1,1]return = 1There are 3 ways to cut 4 numbers into 3 parts. [2] | [5] | [1,1]: the middle sum 5 is more than 2 + 2 = 4, so it fails. [2] | [5,1] | [1]: 6 is more than 2 + 1 = 3, so it fails. [2,5] | [1] | [1]: 1 is at most 7 + 1 = 8, so it counts. The answer is 1.
Example 2
values = [3,-2,4,-1,2]return = 5The total is 6, so a split counts when its middle sum is at most 3. The 6 splits have middle parts [-2] (sum -2), [-2,4] (2), [-2,4,-1] (1), [4] (4), [4,-1] (3) and [-1] (-1). Only [4] fails. For [4,-1] the outer parts are [3,-2] and [2], with sums 1 and 2, and 3 <= 1 + 2 holds with equality. The answer is 5.
Example 3
values = [1,10,1]return = 0Three numbers allow only one split, [1] | [10] | [1]. The middle sum 10 is more than 1 + 1 = 2, so the answer is 0.
Constraints
3 <= values.length <= 3000-10^4 <= values[i] <= 10^4
More DocuSign Onsite Interview questions
- Count Binary SubstringsONSITE INTERVIEW · Seen Sep 2026
- Two Positions That Add Up to a TargetPHONE SCREEN · ONSITE INTERVIEW · Seen Sep 2026
- Compress Consecutive Integer RangesONSITE INTERVIEW · Seen Aug 2026
- JSON Schema Object ValidatorONSITE INTERVIEW · Seen Aug 2026
- Most Transactions Kept Without Going NegativeONSITE INTERVIEW · Seen May 2025
- Combine Two Sorted Lists Into OneONSITE INTERVIEW · Seen Apr 2022
- Exact Palindrome CheckPHONE SCREEN · ONSITE INTERVIEW · Seen Apr 2022
- Paired Words That Share a SubstringONSITE INTERVIEW · Seen Apr 2022
- Reverse the Characters of a TextPHONE SCREEN · ONSITE INTERVIEW · Seen Apr 2022
- Reverse the Order of a Linked ListONSITE INTERVIEW · Seen Feb 2020
Similar questions at other companies
- Count Subarrays with Equal Even and Odd CountsMicrosoft · ONSITE INTERVIEWMicrosoft interview questions
- Range Booking TotalsGoogle · ONSITE INTERVIEWGoogle interview questions
- Product of Array Except SelfWalmart Labs · ONSITE INTERVIEW
- Subarrays Whose Sum Is a Power of TwoKotak Mahindra Bank · ONSITE INTERVIEWKotak Mahindra Bank interview questions
- Maximize Compatible Car RidersUber Freight · PHONE SCREEN · ONSITE INTERVIEWUber Freight interview questions
- Count Subarrays with Sum KMakeMyTrip.com · ONSITE INTERVIEWMakeMyTrip.com interview questions
- Product Of Array Except SelfInfosys · ONSITE INTERVIEWInfosys interview questions
- Centered K-by-K Submatrix SumsCitadel · ONSITE INTERVIEWCitadel interview questions
- Farthest Affordable Shop per QueryAdobe · ONSITE INTERVIEWAdobe interview questions
- Product of Array Except SelfSquarepoint Capital · ONSITE INTERVIEWSquarepoint Capital interview questions