Ballot Problem with Fixed Number of Ties:
Problem Statement: In an election, candidate A receives $m$ votes and candidate B receives $n$ notes. Let $m \ge n$. In how many ways can the ballots be counted so that ties occur exactly $r$ times ($r \le n$)?
Example: $m = 3, n = 2, r = 1$. There are 4 such scenarios: for order ABAAB, BAAAB the tie occurs at the 2nd vote; for order AABBA, BBAAA the tie occurs at the 4th vote.
Call this number $Z( m,n, r)$. My practical goal is to answer the following: Given the total number of votes $N$, how many ways can we order the ballots to have exactly $r$ ties? It is \begin{equation} Z(N,r) = \sum_{n = r}^{N/ 2} Z( N-n, n ,r ) + \sum_{n = r}^{N/ 2} Z( n, N-n ,r ) \end{equation} once we figure out $Z(m,n,r)$.
It would be nice if one can get $Z(N,r)$ or its generating function directly, but I think the "$r$-tie" ballot problem is interesting on its own.
Mapping to lattice path enumeration
Here is an equivalent form of the problem:
Consider lattice path from $(0,0)$ to point $(m,n)$ with only up $(0,1)$ or right $(1,0)$ movement in $m +n $ steps. Excluding the starting point $(0,0)$, how many lattice paths hit the (lattice point on the) diagonal line $y = x$ exactly $r$ times?
The following figure shows a lattice path that reaches (4,3) and its image under Andre's reflection. It hits the diagonal 3 times.
$r = 0$ is the strictly monotonic path
The $r = 0$ problem can be solved by Andre's reflection principle. (method used here is similar to this ME post)
First of all $m > n$, otherwise the end point $(n,n)$ will be one touching point. Since no touching of the diagonal is allowed, the first step must go right. There are ${ m + n - 1 \choose m-1}$ such paths but we need to exclude the ones that touches the diagonal.
Suppose there is one such path (first step going right) that touches the diagonal, we can do reflection about the $ y= x$ line for the path between the origin and the first intersection (see Figure). The reflected path is one that starts with up movement. Since such paths will definite cross the diagonal line to reach $(m,n)$, it is easy to see that the map is one-to-one. There are ${m+n -1 \choose n - 1}$ such paths.
In sum, the result is \begin{equation} Z( m, n, 0) = { m + n - 1 \choose m - 1 } - {m+n -1 \choose n - 1} = { m + n - 1 \choose n } - {m+n -1 \choose n - 1} \quad m > n \end{equation} which is very similar to the ballot theorem.
Any idea of approaching the general $r$?
Thanks!
Update 1: $m = n, r = 1$ is the strictly monotonic Dyck path
The only intersection is at the end point $(n,n)$, so this is basically a Dyck path that hits the diagonal once. This ME post gives the general result for a Dyck path to hit the diagonal $k$ times. Setting $k$ = 1, the result is $\frac{1}{n}{2n - 2 \choose n-1 }$. Here the path can be either above or below the diagonal line, hence a factor of $2$, \begin{equation} Z( n, n, 1 ) = \frac{2}{n}{2n - 2 \choose n-1 } \end{equation}
Update 2: number of lattice paths that crosses the diagonal $k$ times
Call this number $C( m, n, r )$.
Kern, Malcolm; Walter, Stanley, Ballot theorem and lattice path crossings, Can. J. Stat. 6, 87-90 (1978). ZBL0387.60018. gives the result \begin{equation} C( m,n, r ) = \left\lbrace \begin{aligned} &\frac{2(r+1)}{n} {2n \choose n - r -1 } & m = n \\ &\frac{m - n + 2r + 1}{m + n + 1} { m + n +1 \choose n - r } & m > n \\ \end{aligned} \right. \end{equation}
This is a relevant but different problem. Notice the difference between "touch" and "cross". Only going from one side of $y=x$ to the other is considered as a "cross". In the ballot problem, this is a change of the leading candidate, not a tie. One can check that $C( n, n, 0 )$ is twice the Catalan number.