← 返回 jpmorgan 的题目列表Split Array: Left Sum Greater
类型:qbank
Given an integer array, count how many split positions divide it into a left sublist and a right sublist such that the left sum is greater than the right sum.
Requirements
Input: an integer array.
Choose a split position that creates a non-empty left sublist and a non-empty right sublist.
Count the splits where sum(left) > sum(right).
Return the count.
Notes
Compute total sum once, then sweep split positions while maintaining left_sum.
At split after index i, right_sum = total - left_sum.
Negative numbers change intuition but not the algorithm; do not rely on monotonicity unless constraints guarantee non-negative values.
Preparation
Implement the O(n) prefix sweep.
Test arrays with negative numbers, all positive numbers, length two, and no valid split.