Code wont work for few test cases

eg

4

-1 -1 -1 -2

It produces 0 as output.

How to do in such case ?

Correct output should be -2

please share ur code in cb ide

https://codeshare.io/5eX4jA
This is link to code. CB ide is not working. Kindly use above to view my code. It will expire after 24 hrs.

bro the while loop is running for while num > 0
so since all the values are -ve the sums array always remains 0

refer to the below code if u wish to handle -ve numbers

1 Like

Thanks didi, I got the logic why my code was not running for -ve nos.
In the link provided only 1st sol works for -ve nos, rest all dont work if nos are -ve.

I understood the rest but I cant understand that 1st code…
https://ide.geeksforgeeks.org/SfEXUl37uI

The best explanation for this is


dont think i not trying to explain but there is not better explanation that this for this question.
please go through the long explanation if u get stuck somewhere fell free to ask

1 Like

Thank you I got it…
The code in GeeksForGeeks for C++ gave correct o/p, while when same code in Python3 produced a very large o/p for -ve nos, dont know why ?

You might not have initialised some value, not proficient in python tho.

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.