Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque


def solve():
    H, W = map(int, input().split())
    grid = [['' for _ in range(W)] for _ in range(H)]
    que = deque()
    for i in range(H):
        grid[i] = list(input())
        for j in range(W):
            if grid[i][j] == '#':
                que.append([i, j])
    
    xy = [[0, -1], [1, 0], [0, 1], [-1, 0]]
    ans = 0
    while que:
        n = len(que)
        for _ in range(n):
            y, x = que.popleft()
            for i in range(4):
                xi = x - xy[i][0]
                yi = y - xy[i][1]
                if 0 <= xi <= W-1 and 0 <= yi <= H-1:
                    if grid[yi][xi] == '.':
                        grid[yi][xi] = '#'
                        que.append([yi, xi])
        ans += 1
    print(ans-1)


if __name__ == '__main__':
    solve()

Fixed submission:
from collections import deque


def solve():
    H, W = map(int, input().split())
    grid = [['' for _ in range(W)] for _ in range(H)]
    que = deque()
    for i in range(H):
        grid[i] = list(input())
        for j in range(W):
            if grid[i][j] == '#':
                que.append([i, j])
    
    xy = [[0, -1], [1, 0], [0, 1], [-1, 0]]
    ans = 0
    while que:
        n = len(que)
        for _ in range(n):
            y, x = que.popleft()
            for i in range(4):
                xi = x - xy[i][0]
                yi = y - xy[i][1]
                if 0 <= xi <= W-1 and 0 <= yi <= H-1:
                    if grid[yi][xi] == '.':
                        grid[yi][xi] = '#'
                        que.append([yi, xi])
        ans += 1
    print(ans-1)


if __name__ == '__main__':
    solve()

Buggy python submission (verdict: Runtime Error):
from collections import deque
import numpy as np


def solve():
    H, W = map(int, input().split())
    maze = ['' for _ in range(H)]
    for i in range(H):
        maze[i] = list(input())
    maze = np.array(maze)
    black_l = list(zip(*np.where(maze=='#')))
    que = deque([])
    for x, y in black_l:
        que.append([y, x])
    ans = 0
    
    while len(que) > 0:
        a = len(que)
        for _ in range(a):
            target = que.pop()
            if target[0] != 0:
                if maze[target[0]-1][target[1]] == '.':
                    maze[target[0]-1][target[1]] = '#'
                    que.append([target[0]-1, target[1]])
            if target[0] != H - 1:
                if maze[target[0]+1][target[1]] == '.':
                    maze[target[0]+1][target[1]] = '#'
                    que.append([target[0]+1, target[1]])
            if target[1] != 0:
                if maze[target[0]][target[1]-1] == '.':
                    maze[target[0]][target[1]-1] = '#'
                    que.append([target[0], target[1]-1])
            if target[1] != W - 1:
                if maze[target[0]][target[1]+1] == '.':
                    maze[target[0]][target[1]+1] = '#'
                    que.append([target[0], target[1]+1])
        ans += 1
    
    print(ans-1)


if __name__ == '__main__':
    solve()

Fixed submission:
from collections import deque


def solve():
    H, W = map(int, input().split())
    grid = [['' for _ in range(W)] for _ in range(H)]
    que = deque()
    for i in range(H):
        grid[i] = list(input())
        for j in range(W):
            if grid[i][j] == '#':
                que.append([i, j])
    
    xy = [[0, -1], [1, 0], [0, 1], [-1, 0]]
    ans = 0
    while que:
        n = len(que)
        for _ in range(n):
            y, x = que.popleft()
            for i in range(4):
                xi = x - xy[i][0]
                yi = y - xy[i][1]
                if 0 <= xi <= W-1 and 0 <= yi <= H-1:
                    if grid[yi][xi] == '.':
                        grid[yi][xi] = '#'
                        que.append([yi, xi])
        ans += 1
    print(ans-1)


if __name__ == '__main__':
    solve()

Buggy python submission (verdict: Runtime Error):
from collections import deque
import numpy as np


def solve():
    H, W = map(int, input().split())
    maze = ['' for _ in range(H)]
    for i in range(H):
        maze[i] = list(input())
    maze = np.array(maze)
    black_l = list(zip(*np.where(maze=='#')))
    que = deque([])
    for x, y in black_l:
        que.append([y, x])
    ans = 0
    
    while len(que) > 0:
        a = len(que)
        for _ in range(a):
            target = que.pop()
            if target[0] != 0 and maze[target[0]-1][target[1]] == '.':
                maze[target[0]-1][target[1]] = '#'
                que.append([target[0]-1, target[1]])
            if target[0] != H - 1 and maze[target[0]+1][target[1]] == '.':
                maze[target[0]+1][target[1]] = '#'
                que.append([target[0]+1, target[1]])
            if target[1] != 0 and maze[target[0]][target[1]-1] == '.':
                maze[target[0]][target[1]-1] = '#'
                que.append([target[0], target[1]-1])
            if target[1] != W - 1 and maze[target[0]][target[1]+1] == '.':
                maze[target[0]][target[1]+1] = '#'
                que.append([target[0], target[1]+1])
        ans += 1
    
    print(ans-1)


if __name__ == '__main__':
    solve()

Fixed submission:
from collections import deque


def solve():
    H, W = map(int, input().split())
    grid = [['' for _ in range(W)] for _ in range(H)]
    que = deque()
    for i in range(H):
        grid[i] = list(input())
        for j in range(W):
            if grid[i][j] == '#':
                que.append([i, j])
    
    xy = [[0, -1], [1, 0], [0, 1], [-1, 0]]
    ans = 0
    while que:
        n = len(que)
        for _ in range(n):
            y, x = que.popleft()
            for i in range(4):
                xi = x - xy[i][0]
                yi = y - xy[i][1]
                if 0 <= xi <= W-1 and 0 <= yi <= H-1:
                    if grid[yi][xi] == '.':
                        grid[yi][xi] = '#'
                        que.append([yi, xi])
        ans += 1
    print(ans-1)


if __name__ == '__main__':
    solve()