There are 9 students in a class. Among them, three of them are from the department of math; three are from the Department of medicine, and the other three from the Department of sociology. How many ways can they stand in a line such that no three consecutive students are from the same department?
Just wanted to check my work. I was thinking of using principle inclusion and exclusion, my reasoning was that total numbers is 9! so we subtract the number of ways they can stand consecutively.
The number of ways we can arrange such that we have one department of consecutive students in our line is: $$\binom{3}{1}3! \cdot 7!$$
The number of ways we can arrange such that we have two department of consecutive students in our line is: $$\binom{3}{2}5! \cdot 3! \cdot 3!$$
The number of ways we can arrange such that we have three department of consecutive students in our line is: $$\binom{3}{3}5! \cdot 3! \cdot 3!$$
This gives us the final answer: $$9!-\left[\binom{3}{1}3! \cdot 7!-\binom{3}{2}5! \cdot 3! \cdot 3!+\binom{3}{3}5! \cdot 3! \cdot 3!\right]$$
There is a small typo in your last term. It should read $$\binom33*3!*(3!)^3$$ where there are now three blocks of same-department students, and only those three blocks, so there are $3!$ ways to arrange the blocks. Then $(3!)^3$ is the number of permutations of students within the blocks.
But otherwise your answer is correct.