PROBLEM LINK:
Author:Vivek Hamirwasia
Tester:Gerald Agapov
Editorialist:Jingbo Shang
DIFFICULTY:
Cakewalk
PREREQUISITES:
Programming Language.
PROBLEM:
Determine whether the given binary string contains the substring (consecutive) "010" or "101".
EXPLANATION:
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 :P
AUTHOR'S AND TESTER'S SOLUTIONS:
Solutions will be uploaded soon.
Author's solution can be found here.
Tester's solution can be found here.