You are viewing a single comment's thread. Return to all comments →
O(n) prefix sum solution in Golang
func birthday(s []int32, d int32, m int32) int32 { prefixSums := make([]int32, len(s)+1) for i, n := range s { prefixSums[i+1] = prefixSums[i] + n } var countOfSegments int32 for i := m; i < int32(len(prefixSums)); i++ { if prefixSums[i] - prefixSums[i-m] == d { countOfSegments++ } } return countOfSegments }
Seems like cookies are disabled on this browser, please enable them to open this website
Subarray Division 2
You are viewing a single comment's thread. Return to all comments →
O(n) prefix sum solution in Golang