DEV Community

Discussion on: Backspace String Comparisons: Two Ways To Approach a Common Algorithm

Collapse
 
khuongduybui profile image
Duy K. Bui

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).

Collapse
 
andreasanta profile image
Andrea S.

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 #.