Given a list of numbers, stop processing input after the cumulative sum of all the input becomes negative

fallig all testcase except first one

link of code

i am not able to find my mistake plz help

Hey @anandprakash1091971, instead of taking the input as a single list of numbers , you can follow this approach :

Initialise an empty list and sum variable to zero.

  1. Use an infinite loop.
  2. Now inside the loop, take a single integer as input from the user.
  3. Then inside the loop only, add it to sum variable.
  4. Now if the sum is greater than zero, then you can append the input integer of this iteration to a new empty list.
  5. And if sum<0, then you can break the loop.
  6. In the end(outside the loop) you just need to print the elements of the new list created (every element in a new line).

Your approach is not working as your are inputting all the integers in a single line (using a space bar right ?)
But the test cases are so designed that each input is in a separate line which can be achieved using the above approach.

Hope this helps.
All the Best :slight_smile:

1 Like