Suppose we ask about the expected maximum run length when we select $m$ elements from a total of $n.$
For a run length at most $k$ we must first choose a run of some length
possibly preceded by a gap, giving (the variable $w$ counts the number
of elements in the tuple)
$$\frac{1}{1-z} \sum_{q=1}^k w^q z^q $$
followed by a sequence of gaps followed by a run
$$\frac{z}{1-z} \sum_{q=1}^k w^q z^q$$
possibly followed at the end by another gap
$$\frac{1}{1-z}.$$
This gives the generating function
$$f_k(z,w) = \frac{1}{(1-z)^2} \left(\sum_{q=1}^k w^q z^q \right)
\sum_{p\ge 0} \left( \frac{z}{1-z} \sum_{q=1}^k w^q z^q \right)^p.$$
We are interested in the total count from
$$[z^n] [w^m]
\sum_{k=1}^m k (f_k(z,w) - f_{k-1}(z, w))
\\ = [z^n] [w^m]
\left(m f_m(z,w) - \sum_{k=1}^{m-1} f_k(z, w)\right).$$
The sum component in $f_k(z, w)$ is
$$\sum_{p\ge 0}
\left( \frac{wz^2}{1-z} \sum_{q=0}^{k-1} w^q z^q \right)^p
\\ = \frac{1}{1-wz^2(1-w^k z^k)/(1-z)/(1-wz)}.$$
At this point it appears that we are better off working with
$$g_k(z,w) = \frac{1}{(1-wz)^2} \left(\sum_{q=1}^k z^q \right)
\sum_{p\ge 0} \left( \frac{wz}{1-wz} \sum_{q=1}^k z^q \right)^p$$
which gives for the sum component
$$\sum_{p\ge 0} \left( \frac{wz^2}{1-wz} \sum_{q=0}^{k-1} z^q \right)^p
\\ = \frac{1}{1-wz^2(1-z^k)/(1-wz)/(1-z)}.$$
This yields
$$g_k(z,w) = \frac{1}{1-wz} \left(\sum_{q=1}^k z^q \right)
\frac{1}{1-wz-wz^2(1-z^k)/(1-z)}
\\ = \frac{1}{1-wz} \left(\sum_{q=1}^k z^q \right)
\frac{1}{1-w(z-z^2+z^2(1-z^k))/(1-z)}
\\ = \frac{1}{1-wz} \left(\sum_{q=1}^k z^q \right)
\frac{1}{1-w(z-z^{k+2}))/(1-z)}.$$
Extracting the coefficient on $[w^{n-m}]$ we get
$$\left(\sum_{q=1}^k z^q \right)
\sum_{p=0}^{n-m} z^{n-m-p} \frac{z^p(1-z^{k+1})^p}{(1-z)^p}
\\ = z^{n-m} \left(\sum_{q=1}^k z^q \right)
\sum_{p=0}^{n-m} \frac{(1-z^{k+1})^p}{(1-z)^p}
\\ = z^{n-m}
\left(\left(\frac{1-z^{k+1}}{1-z}\right)^{n-m+1}-1\right).$$
Extracting the coefficient on $[z^n]$ we obtain
$$[z^n] z^{n-m}
\left(\frac{1-z^{k+1}}{1-z}\right)^{n-m+1}
= [z^m] \left(\frac{1-z^{k+1}}{1-z}\right)^{n-m+1}.$$
This is
$$\sum_{p=0}^{\lfloor m/(k+1)\rfloor}
{n-m+1\choose p} (-1)^p {n-m+m-p(k+1)\choose n-m}
\\ = \sum_{p=0}^{\lfloor m/(k+1)\rfloor}
{n-m+1\choose p} (-1)^p {n-p(k+1)\choose n-m}.$$
Substitute this into the summation formula to obtain
$$m {n\choose m}
- \sum_{k=1}^{m-1} \sum_{p=0}^{\lfloor m/(k+1)\rfloor}
{n-m+1\choose p} (-1)^p {n-p(k+1)\choose n-m}
\\ = {n\choose m}
- \sum_{k=1}^{m-1} \sum_{p=1}^{\lfloor m/(k+1)\rfloor}
{n-m+1\choose p} (-1)^p {n-p(k+1)\choose n-m}.$$
This is
$${n\choose m}
+ \sum_{p=1}^m
{n-m+1\choose p} (-1)^p {n-p\choose n-m}
\\ - \sum_{k=0}^{m-1} \sum_{p=1}^{\lfloor m/(k+1)\rfloor}
{n-m+1\choose p} (-1)^p {n-p(k+1)\choose n-m}
\\ = {n\choose m}
+ \sum_{p=1}^m
{n-m+1\choose p} (-1)^p {n-p\choose n-m}
\\ - \sum_{1\le pq \le m}
{n-m+1\choose p} (-1)^p {n-pq\choose n-m}.$$
Now we do one last simplification on the first and the second term
together which are
$$\sum_{p=0}^m
{n-m+1\choose p} (-1)^p {n-p\choose n-m}$$
and introduce for use with the Egorychev method
$${n-p\choose n-m} = {n-p\choose m-p}
= \frac{1}{2\pi i}
\int_{|z|=\epsilon}
\frac{1}{z^{m-p+1}} (1+z)^{n-p} \; dz.$$
Note that this is zero when $p\gt m$ so we may extend $p$ to infinity,
getting
$$\frac{1}{2\pi i}
\int_{|z|=\epsilon}
\frac{1}{z^{m+1}} (1+z)^{n}
\sum_{p\ge 0} {n-m+1\choose p} (-1)^p \frac{z^p}{(1+z)^p}
\; dz
\\ = \frac{1}{2\pi i}
\int_{|z|=\epsilon}
\frac{1}{z^{m+1}} (1+z)^{n}
\left(1-\frac{z}{1+z}\right)^{n-m+1}
\; dz
\\ = \frac{1}{2\pi i}
\int_{|z|=\epsilon}
\frac{1}{z^{m+1}} (1+z)^{n}
\frac{1}{(1+z)^{n-m+1}}
\; dz
\\ = \frac{1}{2\pi i}
\int_{|z|=\epsilon}
\frac{1}{z^{m+1}} (1+z)^{m-1}
\; dz = [z^m] (1+z)^{m-1} = 0.$$
Dividing by ${n\choose m}$ for the expectation
and without the zero contribution from the first two terms
we thus obtain for the expectation of the maximum run length
$${\large\color{#080}{{n\choose m}^{-1} \sum_{1\le pq \le m}
{n-m+1\choose p} (-1)^{p+1} {n-pq\choose n-m}}}.$$
The reader is invited to prove this in a different way,
perhaps without using ordinary generating functions.
The Maple code that was used to verify these including a total
enumeration routine was as follows:
with(combinat);
sr :=
proc(n, m)
local sel, sel2, maxr, cur, res, pos;
sel := firstcomb(n, m);
res := 0;
while type(sel, `set`) do
sel2 := convert(sel, `list`);
maxr := -1; cur := 1;
for pos from 2 to m do
if sel2[pos] = 1 + sel2[pos-1] then
cur := cur + 1;
else
if cur > maxr then
maxr := cur;
fi;
cur := 1;
fi;
od;
if cur > maxr then
maxr := cur;
fi;
res := res + maxr;
sel := nextcomb(sel, n);
od;
res;
end;
f :=
proc(k)
local base;
base := add(w^q*z^q, q=1..k);
1/(1-z)^2*base*sum((z/(1-z)*base)^p, p=0..infinity);
end;
Hf :=
proc(m)
m*f(m)-add(f(k), k=1..m-1);
end;
Qf :=
proc(n, m)
coeftayl(coeftayl(Hf(m), w=0, m), z=0, n);
end;
g :=
proc(k)
local base;
base := add(z^q, q=1..k);
1/(1-w*z)^2*base*sum((w*z/(1-w*z)*base)^p, p=0..infinity);
end;
Hg :=
proc(m)
m*g(m)-add(g(k), k=1..m-1);
end;
Qg :=
proc(n, m)
coeftayl(coeftayl(Hg(m), w=0, n-m), z=0, n);
end;
X :=
proc(n, m)
local CF;
CF := (n,m,k)->
add(binomial(n-m+1,p)*(-1)^p*binomial(n-p*(k+1), n-m),
p=0..floor(m/(k+1)));
m*binomial(n,m) - add(CF(n,m, k), k=1..m-1);
end;
X1 :=
proc(n, m)
local p, q, res;
res := binomial(n,m) +
add(binomial(n-m+1,p)*(-1)^p*binomial(n-p,n-m), p=1..m);
for p to m do
for q to floor(m/p) do
res := res -
binomial(n-m+1,p)*(-1)^p*binomial(n-p*q,n-m);
od;
od;
res;
end;
X2 :=
proc(n, m)
local p, q, res;
res := 0;
for p to m do
for q to floor(m/p) do
res := res +
binomial(n-m+1,p)*(-1)^(p+1)*binomial(n-p*q,n-m);
od;
od;
res;
end;