Skip to content

Commit 294fadb

Browse files
committed
feat: adds the-grid-search
1 parent c402a9a commit 294fadb

File tree

9 files changed

+196
-0
lines changed

9 files changed

+196
-0
lines changed
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2
2+
10 10
3+
7283455864
4+
6731158619
5+
8988242643
6+
3830589324
7+
2229505813
8+
5633845374
9+
6473530293
10+
7053106601
11+
0834282956
12+
4607924137
13+
3 4
14+
9505
15+
3845
16+
3530
17+
15 15
18+
400453592126560
19+
114213133098692
20+
474386082879648
21+
522356951189169
22+
887109450487496
23+
252802633388782
24+
502771484966748
25+
075975207693780
26+
511799789562806
27+
404007454272504
28+
549043809916080
29+
962410809534811
30+
445893523733475
31+
768705303214174
32+
650629270887160
33+
2 2
34+
99
35+
99
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
YES
2+
NO
Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
2
2+
20 20
3+
34889246430321978567
4+
58957542800420926643
5+
35502505614464308821
6+
14858224623252492823
7+
72509980920257761017
8+
22842014894387119401
9+
01112950562348692493
10+
16417403478999610594
11+
79426411112116726706
12+
65175742483779283052
13+
89078730337964397201
14+
13765228547239925167
15+
26113704444636815161
16+
25993216162800952044
17+
88796416233981756034
18+
14416627212117283516
19+
15248825304941012863
20+
88460496662793369385
21+
59727291023618867708
22+
19755940017808628326
23+
7 4
24+
1641
25+
7942
26+
6517
27+
8907
28+
1376
29+
2691
30+
2599
31+
25 25
32+
7652157548860692421022503
33+
9283597467877865303553675
34+
4160389485250089289309493
35+
2583470721457150497569300
36+
3220130778636571709490905
37+
3588873017660047694725749
38+
9288991387848870159567061
39+
4840101673383478700737237
40+
8430916536880190158229898
41+
8986106490042260460547150
42+
2591460395957631878779378
43+
1816190871689680423501920
44+
0704047294563387014281341
45+
8544774664056811258209321
46+
9609294756392563447060526
47+
0170173859593369054590795
48+
6088985673796975810221577
49+
7738800757919472437622349
50+
5474120045253009653348388
51+
3930491401877849249410013
52+
1486477041403746396925337
53+
2955579022827592919878713
54+
2625547961868100985291514
55+
3673299809851325174555652
56+
4533398973801647859680907
57+
5 4
58+
5250
59+
1457
60+
8636
61+
7660
62+
7848
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
NO
2+
YES
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
1
2+
4 6
3+
123412
4+
561212
5+
123634
6+
781288
7+
2 2
8+
12
9+
34
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
YES
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
1
2+
5 15
3+
111111111111111
4+
111111111111111
5+
111111011111111
6+
111111111111111
7+
111111111111111
8+
3 5
9+
11111
10+
11111
11+
11110
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
YES
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
#!/usr/bin/env python3
2+
3+
import sys
4+
import os
5+
6+
#
7+
# Complete the 'gridSearch' function below.
8+
#
9+
# The function is expected to return a STRING.
10+
# The function accepts following parameters:
11+
# 1. STRING_ARRAY G
12+
# 2. STRING_ARRAY P
13+
#
14+
15+
def gridSearch(G: list[str], P: list[str]) -> str:
16+
"""
17+
Returns a string("YES", "NO") if pattern P has been found in G.
18+
19+
Arguments:
20+
G – the grid to search
21+
P – the pattern to search for
22+
"""
23+
p = P[0]
24+
for i in range(len(G) - len(P) + 1):
25+
start = 0
26+
while True:
27+
start = G[i].find(p, start)
28+
if start == -1:
29+
break
30+
found = True
31+
for j in range(1, len(P)):
32+
if G[i + j][start : start + len(p)] != P[j]:
33+
found = False
34+
break
35+
if found:
36+
return 'YES'
37+
start += 1
38+
return 'NO'
39+
40+
if __name__ == '__main__':
41+
if "FOO" in os.environ:
42+
fptr = open(os.environ['OUTPUT_PATH'], 'w')
43+
else:
44+
fptr = sys.stdout
45+
46+
t = int(input().strip())
47+
48+
for t_itr in range(t):
49+
first_multiple_input = input().rstrip().split()
50+
51+
R = int(first_multiple_input[0])
52+
C = int(first_multiple_input[1])
53+
54+
G = []
55+
for _ in range(R):
56+
G_item = input()
57+
G.append(G_item)
58+
59+
second_multiple_input = input().rstrip().split()
60+
61+
r = int(second_multiple_input[0])
62+
c = int(second_multiple_input[1])
63+
64+
P = []
65+
for _ in range(r):
66+
P_item = input()
67+
P.append(P_item)
68+
69+
result = gridSearch(G, P)
70+
71+
fptr.write(result + '\n')
72+
73+
fptr.close()

0 commit comments

Comments
 (0)