Variant of Bertrand Ballot Problem limiting the difference

The problem is as follows:

Given M ones and N zeroes, how many ways can we construct a string S of length M + N such that:
(1) at any prefix, (number of ones) >= (# of zeroes)
(2) at any prefix, (number of ones) - (number of zeroes) <= M - N (corrected). 

I want to satisfy BOTH constraints.

I already know how to satisfy the first constraint by using a variant of Bertrand's ballot theorem. And the answer is

${\binom {p+q}{q}}{\frac {p+1-q}{p+1}}$

Consider that all permutations that can be constructed are equally likely to occur. I'm trying to find the probability of satisfying the two constraints as one approach. Because when I get that probability formula, then multiply by the total number of ways, I would get the final formula (i.e. number of ways).

I'm stuck at satsifying BOTH constraint. My only progress so far is to figure out that the probability of constraint (1) is equal to the probability of constraint (2).

However, I cannot just multiply the probability twice, because the probability only applies to the total number of ways.

${\binom {p+q}{q}}{\frac {(p+1-q)^2}{(p+1)^2}}$ (wrong)

Any way I could approach this?

I apologize for the poor description and I will improve it as time and feedback passes.


Let me answer a more general question:

Let $m,n,a,b$ be positive integers. How many strings with $m$ ones and $n$ zeroes have the property that in any prefix,

  • # ones $-$ # zeroes $< a$,
  • # ones $-$ # zeroes $>-b$.

Notice that I used strict inequality. Your question is with $a=m-n+1$ and $b=1$.

For now, the best I can do is an answer without proof. For a sketch of a proof in the special case where $m=n$ and $a=b$, see this answer of mine. The idea is that you first use the reflection principle at each boundary. However, paths which hit both boundaries will be subtracted twice, so these must be added back in to correct for this over-subtraction. To count the doubly subtracted paths, you use the reflection principle twice. However, the double counting does not stop there, and you must correct for the paths that hit the walls three times, then four, and so on (until the number of bounces becomes impossible).

It turns out the solution to the general problem is this: $$ \left[\sum_{k}\binom{m+n}{m+k(a+b)}\right]-\left[\sum_{k}\binom{m+n}{n-b+k(a+b)}\right] $$ In both summations, $k$ ranges over all integers for which the lower index of the binomial coefficient is between $0$ and $m+n$, inclusive.

For example, let us say $m=3$ and $n=2$ in your problem. This means that $a=m-n+1=3-2+1=2$, and $b=1$. Therefore, the summations are $$ \left[ \color{gray}{\cdots+\binom{5}{-1}+} \binom{5}2+\binom{5}5 \color{gray}{+\binom{5}8+\cdots} \right] - \left[ \color{gray}{\cdots+\binom{5}{-2}+} \binom{5}1+\binom{5}4 \color{gray}{+\binom{5}7+\cdots} \right]\\ =[10+1]-[5+5]=\boxed{1.} $$ Note that I have extended the summations outside of their bounds to make it more clear how the pattern would continue if $m$ and $n$ were larger. Technically, you can include these extra terms, since they are equal to zero.