Count Splits with Larger Left Sum
Updated
Problem statement
Given an integer array nums, count the places where the sum on the left is strictly greater than the sum on the right.
For this exercise, assume a split divides the array into two nonempty contiguous parts, keeping every element in its original order. A split after index i has left part nums[0..i] and right part nums[i+1..n-1], so 0 <= i < n - 1.
Count the split only when leftSum > rightSum. Equal sums do not count. Return the number of valid splits.
Function
countLeftGreaterSplits(nums: int[]) → intExamples
Example 1
nums = [10,4,-8,7]return = 2The three splits have left/right sums 10/3, 14/-1, and 6/7. Only the first two have a strictly larger left sum, so the answer is 2.
Example 2
nums = [1,1]return = 0There is one split. Both sums are 1, so strict inequality fails and the answer is 0.
Example 3
nums = [-1,-2,-3]return = 1The split sums are -1/-5 and -3/-3. The first split qualifies because -1 is greater than -5; the equal second split does not count.
Constraints
- For this exercise, assume
2 <= nums.length <= 100000. - For this exercise, assume elements may be negative, zero, or positive, with
-10^9 <= nums[i] <= 10^9. - The answer is at most
nums.length - 1.
More NVIDIA Online Assessment questions
- Query a Header-Encoded MatrixOA · Seen Oct 2026
- Maximum ScoreOA · Seen Oct 2026
- Address on Same PageOA · Seen Oct 2026
- Minimize Task Resource ConsumptionOA · Seen Oct 2026
- Minimum Project Bid CostOA · Seen Oct 2026
- Count Ideal Numbers in a RangeOA · Seen Oct 2026
- Generate Bit MaskOA · Seen Oct 2026
- Reconstruct an Array from Prefix XOROA · Seen Oct 2026
- Sum of Subarray MinimumsOA · Seen Oct 2026
- Unique Integers That Sum to ZeroOA · Seen Oct 2026
Similar questions at other companies
- Minimum Positive Starting ValueBooking.com · OA
- Array Interval SumsHeadlands Technologies · OAHeadlands Technologies interview questions
- Minimum AmountBelvedere Trading · OA
- Online No-Intercept Linear RegressionTwo Sigma · OATwo Sigma interview questions
- Range Sum QueriesIntuit · OAIntuit interview questions
- Shortest Distance on a Circular Bus RouteAmazon · OA
- Count Sortable SplitsGoogle · OAGoogle interview questions
- Array Challenge (QR Intern)Akuna Capital · OAAkuna Capital interview questions
- Range Negation UpdatesJP Morgan Chase · OAJP Morgan Chase interview questions
- Threshold AlertsGoldman Sachs · OAGoldman Sachs interview questions