forked from parasjain-12/HackerEarth-Solution
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFind the String.py
More file actions
29 lines (29 loc) · 729 Bytes
/
Find the String.py
File metadata and controls
29 lines (29 loc) · 729 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
t = int(input())
from collections import Counter
for _ in range(t):
n,m = map(int,input().split())
matrix = {}
for i in range(n):
a = list(input())
matrix[i] = Counter(a)
s = input()
l = len(s)
c = 0
c = 0
for i in range(len(s)):
#print("fdefd",s[i],i)
if i<n:
if s[i] in matrix[i] and matrix[i][s[i]]>0:
matrix[i][s[i]] -=1
#print(matrix[i],s[i])
c+=1
else:
j = i%n
if s[i] in matrix[j] and matrix[j][s[i]]>0:
matrix[j][s[i]] -=1
#print("Else",matrix[j])
c+=1
if c==l:
print("Yes")
else:
print("No")