QUERY IN PROBLEM CODE

Here in case the sum at any stage appears to be negative we are making dp[i]=0 for that iteration. what do we do in case all the integers of the array are negative?

e.g. : In case the array is [-2,-1], the ans should be -1, but according to this code, it’s coming out to be zero.

hi @pratyushnitdgp19_2c287088d77b5893
What u can do is first run a loop and check if all numbers are negative or not… if all are negative then, simply print the least negative number, else perform the method as what u are doing…

1 Like

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.