-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Open
Description
Bug Report for https://neetcode.io/problems/surrounded-regions
run code endpoint timeouts when you press 'run' instead of 'submit' with this code in this problem
func solve(board [][]byte) {
rows, cols := len(board), len(board[0])
q := [][2]int{}
add := func(r, c int) {
pos := [2]int{r, c}
if r < 0 || c < 0 || r >= rows || c >= cols || board[r][c] != 'O' {
return
}
board[r][c] = 'T'
q = append(q, pos)
}
for r := range rows {
add(r, 0)
add(r, cols-1)
}
for c := range cols {
add(0, c)
add(rows-1, c)
}
for len(q) > 0 {
f := q[0]
q = q[1:]
r, c := f[0], f[1]
add(r - 1, c)
add(r + 1, c)
add(r, c - 1)
add(r, c + 1)
}
for r := range rows {
for c := range cols {
if board[r][c] == 'O' {
board[r][c] = 'X'
} else if board[r][c] == 'T' {
board[r][c] = 'O'
}
}
}
}Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels