Let $D_n$ be the set of $2n$ coin tosses where the number of $H$'s and $T$'s are never equal as you read from left to right. For example, $$D_2 = \lbrace TTTT, TTTH, TTHT, HHTH, HHHT, HHHH \rbrace.$$ And let $E_n$ be the set of $2n$ coin tosses with $n$ $H$'s and $n$ $T$'s. So $$E_2 = \lbrace TTHH, THTH, THHT, HTTH, HTHT, HHTT \rbrace.$$ I have a proof below that $|D_n| = |E_n|$ for any $n$, but I'm interested in a proof by bijection - can you create a bijection between $D_n$ and $E_n$?
I've tried a few variants of the second proof of the Catalan number formula on Wikipedia, taking an element of $D_n$ as a path that starts from $(0, 0)$ and goes right on $H$ and up on $T$, and flipping parts of the path when the path meets the main diagonal (where the number of $H$'s equals the number of $T$'s). Part of the problem is that the path for an element of $E_n$ can cross the main diagonal repeatedly. I've also tried just switching $H \leftrightarrow T$ from the start of a sequence. E.g. take an element of $E_n$, switch the first coin ($H \leftrightarrow T$) and see if this new sequence in $D_n$. If not, keep any switched coins and continue switching until you get an element of $D_n$. This defines a bijection for $n=1,2$ but doesn't work for any larger $n$ (for $n=3$, $HTHHTT$ isn't mapped to anything).
Proof that $|D_n| = |E_n| = \binom{2n}{n}$
Clearly $|E_n| = \binom{2n}{n}$. There are $2n$ places to put the $T$'s and you choose $n$ of them.
Let $c_n$ be the number of elements of $D_n$ that begin with a $T$. Considering the numbers of $H$'s that can be in this sequence, we have $$c_n = \sum_{h = 0}^{n-1} b_{n,h},$$ where $b_{n,h}$ is the number of elements of $D_n$ that begin with a $T$ and contain $h$ $H$'s. Using a similar argument to the second proof of the Catalan number formula on Wikipedia, you can show that $$b_{n,h} = \binom{2n - 1}{h} - \binom{2n - 1}{h - 1} = \binom{2n}{h} \frac{2n - h}{2n}.$$ Since the number of elements of $D_n$ that begin with an $H$ equal the number that begin with a $T$, the number of elements of $D_n$ is $2c_n$. \begin{align*} 2c_n &= 2\sum_{h=0}^{n-1} \binom{2n}{h} \frac{2n-h}{2n} \\ &= 2\sum_{h=0}^{n-1} \binom{2n}{h} - 4 \sum_{h=1}^{n-1} \binom{2n-1}{h-1} \\ &= \left[2^{2n} - \binom{2n}{n} \right] - 2\left[2^{2n-1} - \binom{2n-1}{n-1} - \binom{2n-1}{n}\right] \\ &= 2\binom{2n-1}{n-1} + 2\binom{2n-1}{n} - \binom{2n}{n} \\ &= \binom{2n}{n}. \end{align*}
A bijection is given in the following paper. I do not know how to access the conference proceedings below, but you can find the paper online (for now), for example at this link: https://people.bath.ac.uk/masadk/papers/catalan.pdf.
I will use their vocabulary, so let me explain:
Furthermore, we need an auxilliary definition:
The authors prove that $|D_n|=|E_n|=|F_n|$. Proposition 2 in the cited paper gives a bijection from $E_n$ to $F_n$. They then modify that to get a bijection between $E_n$ and $D_n$.
These bijections use something called the authors call the "Catalan factorization," which is defined as follows. The input to this method is a finite sequence of zeroes and ones.
Catalan Factorization
Input: A $\{0,1\}$-sequence of length $n$.
Output: An ordered pair $(w,k)$, where $w$ is a $\{0,1,z\}$-sequence of length $n$, and $k$ is a nonnegative integer.
First, underline any two entries in the input which are a $0$ followed by a $1$ with only underlined entries between. Repeat this step until no such entries remain.
Now, the entries which are not underlined will consist of some number of $1$'s, followed by some number of $0$'s. If not, we would not be done with step $1$.
Finally, any entry which is not underlined is replaced with a new symbol, $z$. Call the resulting word $w$. Furthermore, the number of $1$'s which were converted to $z$'s is recorded as a number, $k$. This final result, is $(w,k)$.
The Catalan factorization is injective, and therefore reversible. Given a Catalan factorization $(w,k)$, the corresponding binary string is found by replacing the leftmost $k$ copies of $z$ with $1$, and the remaining copies of $z$ with $0$.
Here are the Catalan factorizations of all of the strings in $E_2$:
Notice the following: because all of the strings in $E_n$ are balanced between zeroes and ones, and because the underlined entries are balanced, then the entries converted to $z$'s must be balanced as well. Therefore, if the Catalan factorization of string in $E_n$ is $(w,k)$, then $w$ must have exactly $2k$ copies of $z$.
Now, let us find the factorizations of all words in $F_2$:
This time, we notice two things. First of all, the second index is always zero (any $z$;'s replaced with $1$'s would imply the existence of a prefix with more ones than zeroes. Secondly, the $w$ parts of $F_2$'s output row correspond bijectively between the $w$ parts of $E_2$'s output row; the only difference is the value of $k$, but this is uniquely forced in both cases. We have discovered this bijection:
Next, we need to modify this to get a bijection between $E_n$ and $D_n$. Here are the last definitions we need.
To give a bijection $E_n\to D_n$, it suffices to give two bijections, one from $E_n^1\to D_n^+$, and another from $E_n^0$ to $D_n^-$.
Why does the bijection applied to a walk in $E_n^1$ yield one in $D_n^+$? Given a walk in $E_n^1$, let its Catalan factorization be $(w,k)$. Necessarily, $w$ begins with a $z$. The result of the bijection replaces all $z$'s with zeroes, so the output path starts with a zero. Furthermore, in $w$, every maximal contiguous sequence of $0$'s and $1$'s will be nonnegative (because these were underlined entries). Therefore, as you read left to right in the output path, the quantity (# zeroes) - (# ones) will start at $+1$, and then it will never go any lower, as desired.
Finally:
At last, we have described the bijection between $E_n$ and $D_n$!