Determine whether the given binary string contains the substring (consecutive) “010” or “101”.
You can use a loop and condition clauses to check directly. Also, you can use some built-in functions to solve this problem too.
For example, C++, we can use
int position = strstr(s, "010") - s;
to get the first occurrence of “010” and check whether this position is in range. Or, if string is used in C++, then
int position = s.find("010");
will work for string.
Similarly, Java, Python, etc… a lot of languages have such functions. Post your accepted solution and let’s find which one is the shortest! I think it will be interesting