Since we are setting the val to 0 when sum gets negative, it won’t work when the entire array contains only negative elements.
What if all the elements are <0. In that case this code won't work right?
@jamesallenvinoy hey Allen when all the elements are negative the same algorithm is followed but there is small modification required this can be implemented using kadane algorithm
you can refer to this link.