Generation

generate functionSun, 13 Nov 2022

Sliding window over a list

func SlidingWindow(v []int, k int) [][]int { n := len(v) - k + 1 windows := make([][]int, n) for i := range windows { windows[i] = v[i : i+k] } return windows }

Questions about programming?Chat with your personal AI assistant