- Joined
- Nov 16, 2022
- Messages
- 1
- Reaction score
- 0
This is the instruction:
You are given two strings. Check, whether second one (called pattern) is a substring of the first one.
Input Format
First line contains string s.
Second line contains string p - pattern.
Constraints
len(s), len(p)<= 1 000 000
Output Format
YES or NO
Sample Input 0
AABB
ABB
Sample Output 0
YES
Sample Input 1
AAABBB
BBBAAA
Sample Output 1
NO
Sample Input 2
AABBABA
BBAA
Sample Output 2
NO
I wrote this but its to slow:
s1 = input()
s2 = input()
k = ''
for i in range(len(s1)):
k = s1
for j in range(i+1,len(s1)):
k += s1[j]
if s2 == k:
break
if s2 == k:
break
if s2 == k:
print("YES")
else:
print("NO")
You are given two strings. Check, whether second one (called pattern) is a substring of the first one.
Input Format
First line contains string s.
Second line contains string p - pattern.
Constraints
len(s), len(p)<= 1 000 000
Output Format
YES or NO
Sample Input 0
AABB
ABB
Sample Output 0
YES
Sample Input 1
AAABBB
BBBAAA
Sample Output 1
NO
Sample Input 2
AABBABA
BBAA
Sample Output 2
NO
I wrote this but its to slow:
s1 = input()
s2 = input()
k = ''
for i in range(len(s1)):
k = s1
for j in range(i+1,len(s1)):
k += s1[j]
if s2 == k:
break
if s2 == k:
break
if s2 == k:
print("YES")
else:
print("NO")