DOUBT IN A HACKERBLOCK QUES

Quest:
https://hack.codingblocks.com/app/contests/1920/206/problem

hello @aaliyah_beg

what doubt u have in this question?

Query: Sir ,how do we get to know the number of inputs that the user wants to give .Shouldn’t the ideal code be :https://ide.codingblocks.com/s/376422 but the accepted code is:https://ide.codingblocks.com/s/376425

@aaliyah_beg

no for this problem u will not be given the number of input.
so u should use while loop and keep reading till ur sum >=0 .

So,sir shoudnt this code also be fully accepted : https://ide.codingblocks.com/s/376430

no , u r iterating only for maximum 5 times
what if u have more than 5 input with sum > =0 .
then in that case u need to iterate furthur right?

so for this problem while loop is good option in place of for becuase we dont know total how may numbers we need to read

Sir we have to use array in this ques and that too of a certain size whether that is 5 or 1000 but we will have to accept a certain number of inputs and we dont know how many numbers will the user provide . Surely we can use while loop in reading the numbers till the condition sum>=0 is satisfied but while accepting we would have to have the loop run till a certain value

no there is no need of array . why are u storing elements ? there is no need to store all elements
simply read numbers one by one in a variable and add it to sum thats it. a single variable is sufficient.

Sir, this should work then :https://ide.codingblocks.com/s/376459

check ur updated code here->

okay , got it sir. Thank you!

you have reopen the doubt
do you have further doubt in it??
what is your doubt now

Sir , dont you think that the code that you have provided will stop working as and when the sum becomes negative and it will not even accept any input further.In online ide user has to put all the input before running but while working this code in sublime text it would not accept all the inputs as requiired. Thats why we should make an array and accept the numbers first and then using while follow the condition.

you need not to make array
because in question it is mention
stop processing input after the cumulative sum of all the input becomes negative.

so the inputs after negative cumulative sum are waste
no need to accept them
we have to print sum before reaching negative cumulative sum

also in array we have limit we can only make array of size 10^6 or 10^7
what if no of input is more than 10^7

okay sir. understood!

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.