An efficient way to compute the average length of streaks of a given number

I think you are looking for run length encoding, which is available in StatsBase

https://juliastats.org/StatsBase.jl/v0.18/misc.html#StatsBase.rle

2 Likes