Where is my logic wrong?

In this problem it’s simply to find out number of ones in a string and then sum from 1 to that number.
but this logic is giving wrong output on submitting…Anyone has idea why this is going wrong when it’s working for the test cases given…??

are you using int? try long long…

using int the answer might overflow according to given constraints.

1 Like

i also falling in the same situation