DEV Community

Discussion on: Solution: Count Binary Substrings

Collapse
 
seanpgallivan profile image
seanpgallivan

It's because we're comparing s[i] to s[i-1], not s[i] - 1. At i = 0, s[i-1] would be undefined, so we can't find a match until i = 1.

Thinking about it a different way, any matching substring has to be of even length (since it has an equal amount of 0's and 1's), so the first possible matching substring is when i = 1.

Collapse
 
malikmoss profile image
malikmoss

It just clicked. Thanks alot!

Thread Thread
 
seanpgallivan profile image
seanpgallivan

You're welcome!