Problem statement

https://binarysearch.com/problems/Finding-Binary-Search-in-a-String/

Solution

We can do bruteforce here: check all possible candidates of length m = 11: we have O(n) cases for start and O(n//m) cases for step, so in total we need to check O(n^2) cases.

Complexity

It is O(n^2) for time and O(m) for space, where m = 11 here.

Code

class Solution:
    def solve(self, s):
	n = len(s)
        return any(s[i:i+d*12:d]=="binarysearch" for d in range(1, n//11+1) for i in range(n-11*d))