How to solve this confusing permutation problem related to arrangement of books?
HINT:
$$\underbrace{\underbrace{M_1M_2M_3M_4}_{4!}\mid\underbrace{C_1C_2C_3}_{3!}\mid\underbrace{H_1H_2}_{2!}\mid\underbrace{L_1}_{1!}}_{4!}$$
you have already excellent answers so i will try to give you a nice way on how to see the problem.
Suppose that the books of the same category are all in a custody,so we have a custody for math,chemistry,history and language: $4$ custodies in total.
Now the question is: in how many ways can you arrange those 4 custodies? The answer is clearly $4!$. Now what is left is the number of arrangements of books in the same custody,therefore we have $4!\cdot 3! \cdot 2! \cdot 1!$ and you can do that for every arrangement of the $4$ custodies .,therefore you have finally $4!(4! \cdot 3! \cdot 2! \cdot 1!) $
You treat books of same subject as one object (since they have to be together) so you have $ 4!$ options. And then comes your part in which you permute books of same subject. So the final result is $4!4!3!2!1!$.