Isn't the point of having 2 pointers is to have them move together?
I think if you rewrite your if / else chain a little bit and break it out into 2 separate if blocks, then you can always decrease i and j together (at least until one of them reaches 0).
I agree the idea of starting from the end simplifies things, but the if blocks should be broken into three groups. Sometimes I even use a while loop per string to skip all consecutive occurrences of #.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Isn't the point of having 2 pointers is to have them move together?
I think if you rewrite your if / else chain a little bit and break it out into 2 separate if blocks, then you can always decrease i and j together (at least until one of them reaches 0).
I agree the idea of starting from the end simplifies things, but the if blocks should be broken into three groups. Sometimes I even use a while loop per string to skip all consecutive occurrences of #.