 # The tester for Python works poorly

#1

Unfortunately I couldn’t submit a correct solution since it wasn’t clear which output should be retrieved or printed when submitting the code in Python. After about 10 minutes of trying several formatting, I gave up and looked at the solution. I lost all points even though I solved the original problem in less than 20 minutes.

However, the main purpose of this message is for you to update the tester.

My solution is attached:
import uuid

class Solution:
# @param A : list of list of chars
def solve(self, A):
A = [list(s) for s in A]

``````    n = len(A)
m = len(A)
visited = set()
islands = {}
valid_regions = {}

for i in range(n):
for j in range(m):
if A[i][j] == 'O' and (i, j) not in visited:
island_id = str(uuid.uuid4())
islands[island_id] = set([(i ,j)])
valid_regions[island_id] = True

stack = [(i, j)]
while stack:
curr_i, curr_j = stack.pop()
if 0 <= curr_i < n and 0 <= curr_j < m:
if curr_i == 0 or curr_i == n-1 or curr_j == 0 or curr_j == m-1:
if A[curr_i][curr_j] == 'O':
valid_regions[island_id] = False

if A[curr_i][curr_j] == 'O':

for d1 in range(-1, 2):
for d2 in range(-1, 2):
if abs(d1) + abs(d2) <= 1:
expand_i = curr_i + d1
expand_j = curr_j + d2
if (expand_i, expand_j) not in visited: