← 返回 amazon 的题目列表Non-Zero Load Sum
类型:online_judge
Given an integer list queueMessages, determine the minimum number of integers that can be inserted into queueMessages so that no subarray sums to zero. Implement a function minInsertionsForNonZeroSum that takes an integer list queueMessages and returns the minimum number of integers required to be inserted.
Input:
queueMessages = [1, -5, 3, 2, -5]
Output: 1
Explanation: One way is to insert 100 after the third position, transforming the array into [1, -5, 3, 100, 2, -5], with no subarray summing to zero. Therefore, the minimum number of messages to be inserted is 1.
Example
Input
[1, -5, 3, 2, -5]