2657. Find the Prefix Common Array of Two Arrays
Solution
func findThePrefixCommonArray(A []int, B []int) []int {
n := len(A)
resp := make([]int, n)
bMap := make(map[int]bool, n)
aMap := make(map[int]bool, n)
for i:=0; i<n; i++ {
aMap[A[i]]=true
bMap[B[i]]=true
count := 0
for k := range aMap {
if bMap[k] {
count++
}
}
resp[i]=count
}
return resp
}

Previous2610. Convert an Array Into a 2D Array With ConditionsNext3042. Count Prefix and Suffix Pairs I
Last updated