## String Finding

View as PDF

Points: 5
Time limit: 1.0s
Memory limit: 64M

Author:
Problem type

You have a string (indexed from ) with no more than lowercase characters. Find the first occurrence of a string , or print -1 if is not a substring of .

#### Input Specification

The first line will have the string .
The second line will have the string .

#### Output Specification

Print the index of the first occurrence of the string in , or -1 if it is not a substring of .

#### Sample Input

higuyshowsitgoinghiguys
higuys

#### Sample Output

0

• commented on May 5, 2022, 11:28 a.m.

idk how im getting a TLE bc i cant figure ourt how it is TLEING, can someone help me?

• commented on March 21, 2022, 7:33 p.m.

why am i getting a value error using (type str).index(type str) but not using (type str).find(type str)?

• commented on March 21, 2022, 7:59 p.m.

I assume you're using Python. In that case, the proper syntax is (type list).index(type str). The .find method uses type string.

• commented on March 25, 2022, 7:55 p.m.

Thanks for that :)

• commented on July 7, 2017, 9:57 a.m. edited

Is it possible to create a solution for test case # 15 using python 3? I can't seem to run it under the time limit.

• commented on July 7, 2017, 11:28 a.m. edited

Python's builtin find uses Boyer-Moore, which has a worst-case runtime of . Rabin-Karp and KMP are two algorithms which have a worst-case runtime of .