Vending machine problem (combinations) I have the following assignment question

A group of $2N$ people stands in a line in front of a vending machine
to buy drinks, among which each of the $N$ people holds a $5$ dollar coin, and each of the other N people holds a 10 dollar coin. Everyone wants only one can of drink. Drinks are all sold at a price of $5$.If the vending machine cannot give change, i.e., a person puts in
a $10$ dollar coin while there are no $5$ dollar coins in the machine, it will stop working at once.
Assume at the beginning there are no coins in the machine. People holding coins with
the same denomination are considered indistinguishable.
(a) How many queuing ways are there such that the machine will stop working when $N = 3$?
(b)  Let A be the set of all queuing ways that will make the machine stop working.
Each element in A consists of N $5’s$ and N $10’s$, for example, if $N = 2$, an element {5, 10, 10, 5} $∈ A$ denotes the first and forth person holding $5$ coins and
the second and third person holding $10$ dollar coins. The machine will stop working
when the third person puts in the coin in this case. Define a function f, which
maps each element $a ∈ A$ to a sequence of length $2N$ as follows: if the machine
stops working when the $ith$ person puts in the coin in the queuing way a, then in
$f(a)$, the first $i$ numbers would keep unchanged while the following $5’s$ would be replaced by $10’s$ and $10’s$ would be replaced by $5’s$. Let $f(A) = {f(a)|∀a ∈ A}$. What is the cardinality of $|f(A)|$?
(c)How many possible queuing ways are there such that the machine would not stop
working?


I completed part a in a very straightforward way, which is to consider all possible cases. Like the set start with 10,$$\{10,5,.,\} $$ the machine will stop working instantly at position one. Therefore, the possible way to arrange this is $$\frac{5!}{3!2!} =10$$ By following this approach, I got the final answer of 15.
I have some issues while I'm trying to do question $2$, the problem is hard to comprehend and I don't have a way to start with this. Is there any way to start with the problem?Thanks!
 A: Well, this is a classical problem, and the answer is Catalan numbers.
Actually, the (b) question of your problem may seem overcomplicated and unpleasant to solve, but it is the main key to prove the general answer in (c) part. So the (b) question is crucial, really.
Imagine a graph on a coordinate grid, where $x$ varies from $0$ to $2n$. The graph starts at the point $(0;0)$. Now draw a path using the following rule: each guy with a 5-coin is one diagonal step right and upwards, and each guy with a 10-coin is one diagonal step right and downwards. Because there are equal numbers of 5-guys and 10-guys, we end up in $(2n; 0)$.
Then our problem (c) is now reformulated as follows: how many paths are there such that we never fall below the $y=0$ axis?
To find the answer, we will do the following: we count the number of all possible paths and subtract the number of "bad" paths from it. "Bad" means that the path falls below $y=0$ at some point.
The total number of paths is an easy part. There are totally $n$ steps upwards and $n$ steps downwards. We just need to select indices of
steps which are going to be steps upwards (and others become steps downwards automatically). So we just need to choose set of $n$ indices from $2n$-element set of steps. This is the binomial coefficient ${2n \choose n}=\frac{(2n)!}{n!n!}$.
And to find the number of bad paths, let's solve the (b) question. You are suggested to do the following: at the first time when our path falls below zero (and thus touches the line $y=-1$), we reflect the remaining part of this path relative to the horizontal line $y=-1$.
What will happen to the graph then? Our path finished previously at the point $(2n;0)$, but after the reflection the final point will move to $(2n; -2)$. So we will have some path starting from $(0;0)$ as before, but now finishing at $(2n; -2)$.
And so what? Well, the trick is that, given the result path from $(0;0)$ to  $(2n; -2)$, we can restore the original path uniquely: we again find the first point where the path touches $y=-1$ line and reflect the remaining part of the path. It means that we have a bijection between "bad" paths from the original problem and all the paths from $(0;0)$ to  $(2n; -2)$.
And so, number of "bad" paths is equal to total number of paths from $(0;0)$ to  $(2n; -2)$ (and this gives the answer to your (b) question). To calculate this number we should note that we just choose $n-1$ indices corresponding to the steps upwards, and the remaining steps would be steps downwards. So, the number of paths in this case is given by ${2n \choose n-1}=\frac{(2n)!}{(n-1)!(n+1)!}$.
The final answer to the question (c) is exactly what is called the Catalan number and is given by formula
$$
{2n \choose n}-{2n \choose n-1}=\frac{(2n)!}{n!n!}-\frac{(2n)!}{(n-1)!(n+1)!}=\frac{(2n)!(n+1)-(2n)!n}{n!(n+1)!}=\frac{(2n)!}{n!(n+1)!}=\frac{1}{n+1}{2n \choose n}.
$$
