It allocates a lot because it does two copies of the list when taking slices. I wrote it that way for simplicity, but a better way to write it would be the following:
a = @view seq[begin:end-1]
b = @view seq[begin+1:end]
countmap(zip(a, b))
This should not allocate as much.