You are viewing a single comment's thread. Return to all comments →
can be solved in O(n)
func countTriplets(arr []int64, r int64) int64 { pair := map[int64]int{} triple := map[int64]int{} count := 0 for _, v := range arr{ if c, ok := triple[v]; ok{ count += c } if c, ok := pair[v]; ok{ triple[v*r] += c } pair[v*r]++ } return int64(count) }
Seems like cookies are disabled on this browser, please enable them to open this website
Count Triplets
You are viewing a single comment's thread. Return to all comments →
can be solved in O(n)