I had a hard time figuring out bug in this. can someone identify the bug n based on question below in 3 or less than 3 lines.
In any event consisting of an integers is given a slice of that OK array is a pair of integers (P,Q) such that (P,Q) lies in the range of 0 to N. A slice (P,Q) of Array A is called non negative if all the elements A[P] A[P+1], A[Q-1],A[Q] are not negative. the sum of the slice (P,Q) of an array is the value A[P] A[P+1], A[Q-1],A[Q] . you are given the implementation of a function given an array A of consisting of N integers and return the maximum sum of any non negative slice in that array function returns -1 if there are no negative slices in that array
Example A[0] = 1, A[1] = 2, A[2] = -3, A[3] = 4, A[4]= 5, A[5] = -6 , the function should return 9.
Def solution ( S) :
Max_sum = 0
Current_sum = 0
Positive = False
N = len(S)
For i in range(n):
Item = S[i]
If item < 0 :
If max_sum < current_sum :
Max_sum = current_sum
current_sum = 0
Else:
Positive = True
current_sum = +=item
if current_Sum> max_sum :
max_sum = current_sum
if positive :
return max_sum
return -1