zonedout's blog

By zonedout, history, 2 days ago, In English

556A - Case of the Zeros and Ones

HERE is my code:

it fails on test 12. the input is not totally visible since its a long no. the output to test 12 should have been 0(according to the site) but am getting the output as 199996

Tags 900
  • Vote: I like it
  • +2
  • Vote: I do not like it

»
2 days ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by zonedout (previous revision, new revision, compare).

»
2 days ago, # |
  Vote: I like it 0 Vote: I do not like it

Auto comment: topic has been updated by zonedout (previous revision, new revision, compare).

»
2 days ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

i don't know about your approach but i think the difference of the number of 0s and 1s in the string solves the problem (as you can always eliminate one 1 and one 0 from the string so remaining extra will be the ans)

»
36 hours ago, # |
  Vote: I like it 0 Vote: I do not like it

Try to solve it using stack. Here's my solution:SOL

»
33 hours ago, # |
Rev. 2   Vote: I like it 0 Vote: I do not like it

I think you are using std::string::erase wrongly. Please read some documentations if you are unsure of what you do.

In your specific case, I'm understanding that you want to erase index i and i+1; in which case, the correct call should be str.erase(i, 2) instead of str.erase(i, i+1).