• + 0 comments

    Python 3 (using regex)

    def gridSearch(G, P):
        string = "".join(G)
        separation = C-c
        if separation < 0:
            return "NO"
        pattern = fr'.{{{separation}}}'.join(P)
        for match in re.finditer(pattern, string):
            rows = (match.end()-1)//C - match.start()//C + 1
            if rows == r:
                return "YES"
        return "NO"