Você está na página 1de 2

Question: Write a function named findPattern, that takes as argument a string consisting of 0 and 1 characters.

The function returns position of the first pattern of at least 3 characters that occurs twice in the string. Examples: A) I------------------------------------| |------------------------------------| 1 0 1 0 1

Function should return 0. As the pattern 101 is repeated in the string and first occurrence is at position 0 . B) I------------------------------------| |------------------------------------| 0 0 0 1 0 0 0 0 0

Function should return 1. As the pattern 001 is repeated in the string and first occurrence is at position 1. C) 0

Function should return -1. As no pattern of three characters is repeated.

Você também pode gostar