• + 0 comments

    Python3

    def gridSearch(G, P):
        pattern_len = len(P)
        single_pattern_len = len(P[0])
        
        patter_index = None
        for c, row in enumerate(G):
            
            row_temp = row
            pattern_row_index, pattern_col_index = c, 0
            while P[0] in row_temp:
                patter_index = row_temp.index(P[0])
                pattern_col_index += patter_index
    
                is_match = True
                for i in range(1, pattern_len):
                    if G[pattern_row_index+i][pattern_col_index:][:single_pattern_len] != P[i]:
                        is_match = False
                        break
                pattern_col_index += 1
                row_temp = row_temp[patter_index+1:]
                if is_match: return "YES"
        return "NO"