I\'m looking for an more efficient alternative to brute force for finding the longest sub array of an array with a non-negative sum. The numbers range from -5 to 5 in this a
you can keep track of 11 things for each element while using dynamic programming, moving from left to right. Those 11 things correspond to the following possible sum :
-5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5
For each of these you need to store the left most index, such that sum of the subarray starting at that index and ending in the current index gives that much sum.
This is not a complete solution, but I believe this may serve the purpose of hint.