$9$ different people must be put in a row.
Three of them are of nationality $X$, three are of $Y$, and the remaining three are of $Z$.
In how many combinations there will be no two people of the same nationality sitting next to each other?
My understanding:
I couldn't find a pattern to follow if few are already occupied. Like, if the first seat is occupied by a person of nationality $X$ then the next seat can be occupied by $6$ other people from $Y$ or $Z$, and then the tree grows where I can't seem to have a control on.
Any hints will be appreciated.
If you are not familiar with the Inclusion-Exclusion Principle, observe that there are $\binom{6}{3}$ ways to arrange three $X$s and three $Y$s (ignoring permutations of the individuals within a country for now). Consider those that begin with $X$.
$\color{red}{XXXYYY}$
$\color{blue}{XXYXYY}$
$\color{blue}{XXYYXY}$
$\color{green}{XXYYYX}$
$\color{blue}{XYXXYY}$
$XYXYXY$
$\color{brown}{XYXYYX}$
$\color{blue}{XYYXXY}$
$\color{brown}{XYYXYX}$
$\color{green}{XYYYXX}$
It is not possible to insert three $Z$s in the arrangement $\color{red}{XXXYYY}$ to separate the $X$s and $Y$s.
In the arrangements $\color{green}{XXYYYX}$ and $\color{green}{XYYYXX}$, there is only one way to insert the $Z$s to separate the $X$s and $Y$s since a $Z$ must be inserted wherever two consecutive identical letters appear.
In the arrangements $\color{blue}{XXYXYY, XXYYXY, XYXXYY, XYYXXY}$, two $Z$s must be used to separate consecutive identical letters. Once this is done, we are left with five places to insert the remaining $Z$. For instance, with the arrangement $\color{blue}{XZXYXYZY}$, the remaining $Z$ can be inserted in one of the spaces indicated by a square.
$\color{blue}{\square XZX \square Y \square X \square YZY \square}$
In the arrangements $\color{brown}{XYXYYX}$ and $\color{brown}{XYYXYX}$, one $Z$ must be inserted in order to separate consecutive identical letters. To ensure that identical letters are separated, we must choose two of the six spaces adjacent to $X$ or $Y$ but not $Z$ in which to insert the remaining $Z$s. For instance, in the arrangement of $XYXYZYX$, we must choose two of he spaces indicated by a square in which to insert the remaining $Z$s.
$\color{brown}{\square X \square Y \square X \square YZY\square X\square}$
In the arrangement $XYXYXY$, we must choose three of the seven spaces indicated by a square in which to insert the $Z$s.
$\square X \square Y \square X \square Y \square X \square Y \square$
By symmetry, there are an equal number of permissible arrangements in those permutations created by interchanging the roles of $X$ and $Y$.
Finally, observe that within each of these arrangements, people of the same nationality can be permuted in $3!$ ways, so we must multiply the number of permissible arrangements of three $X$s, three $Y$s, and three $Z$s by $(3!)^3$.