We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
It's not a dumb mistake I would say. It's a very good corner scenario. For those who are still in fix as to what to do for this test case, note that you have to find the overlapping matches and for that you have to perform a 'lookahead' in your regex. e.g . In Python it as shown below:
str1 = '111111111111111'
str2 = '11111' -> This is variable
pattern = '(?=' + str2 + ')'
print([m.start() for m in re.finditer(str2, str1)])
Output:
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
Cookie support is required to access HackerRank
Seems like cookies are disabled on this browser, please enable them to open this website
The Grid Search
You are viewing a single comment's thread. Return to all comments →
It's not a dumb mistake I would say. It's a very good corner scenario. For those who are still in fix as to what to do for this test case, note that you have to find the overlapping matches and for that you have to perform a 'lookahead' in your regex. e.g . In Python it as shown below:
str1 = '111111111111111'
str2 = '11111' -> This is variable
pattern = '(?=' + str2 + ')'
print([m.start() for m in re.finditer(str2, str1)])
Output:
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]