Untitled
unknown
plain_text
9 months ago
430 B
4
Indexable
func firstCompleteIndex(arr []int, mat [][]int) int {
mp := make(map[int][2]int)
n := len(mat)
m := len(mat[0])
for i := 0; i < n; i++ {
for j := 0; j < m; j++ {
mp[mat[i][j]] = [2]int{i, j}
}
}
row := make(map[int]int)
col := make(map[int]int)
for i, num := range arr {
p := mp[num]
row[p[0]]++
if row[p[0]] == m {
return i
}
col[p[1]]++
if col[p[1]] == n {
return i
}
}
return 0
}Editor is loading...
Leave a Comment