Incorrect implementation

Report a typo

Below is the described substring searching algorithm:

def contains(text, pattern):
    for i in range(len(text) - len(pattern)):
        found = True

        for j in range(len(pattern)):
            if text[i + j] != pattern[j]:
                found = False
                break

        if found:
            return True

    return False

This version contains a mistake. Select all pairs of strings (the first is text, the second is pattern), for which the algorithm above gives an incorrect output.

Select one or more options from the list

Create a free account to access the full topic