How many ways to arrange ABCD such that A precedes B, and C precedes D Restriction 1: A precedes B
Restriction 2: C precedes D
Note: They can be either adjacent or not.
For example,
ABCD
ACBD
ACDB
CABD
CDAB
but
CBAD 
ABDC 
are not allowed and so on, as long as A comes before B and C comes before D.
Is there a generalized way to solve such problems?
Another similar problem to the above is finding the number of arrangements of  ABCDE if 
Restriction 1: A precedes B, B precedes C
Restriction 2: D precedes E
e.g. 
ABCDE
ADBCE
DEABC
 A: There are in total $4!=24$ ways to arrange $ABCD$. Exactly half of them will have $B$ before $A$, and exactly half of them will have $D$ before $C$. Since the relative ordering of $A$ and $B$ is clearly independent of the relative ordering of $C$ and $D$, under those restrictions, the total number of ways to arrange the items is $24/(2\cdot 2) = 6$.
A: First we notice there are not restrictions on $B,D$ so we place them down.
$$B,D$$
There are 2 ways to rearrange this.
Now we'll consider our first restriction for $A$  the only possible place we can add A is before B so now our list looks like this.
$$A,B,D$$
There are still only 2 ways since $A$ has only one possible position.
Now we'll our second restriction. Notice how $C$ can be placed in 3 possible places: Between $BD,AB$ and before $A$. so we end up with
$$A,B,C,D$$ which has $(2!)(1!)(3!)$ ways of rearranging.
In general you can go through this process for any permutation with restrictions as long as you start with the elements that have no restrictions on them.
A: I try to solve it by generalize method so that we can apply this for other cases also.
We A, B, C, D.
If we fix A on first place and B on last place. Then second and third place can be filled in 1! * 1!. So number of ways = 1 * 1! * 1! * 1 = 1 
So if the pair is on first and last place so we have only 1 way. So for C is on first place and D on last place we have 1 way.
If pair is not on first and last place. Then,
A is on first place and D. Either B is on second or third. And third position is filled with remaining.
Ways = 1 * 2! * 1! * 1 = 2
Similarly for C is on first and B on last. Then,
Ways = 1 * 2! * 1! * 1 = 2
Total ways = 1 + 1 + 2 + 2 = 6.
Note -
So if n pairs then if pair elements on first and last position then ways n * (n-1)!
If pair element not on first and last place then ways n * n! 
So total ways = n * (n-1)! + n * n!
