Combinatorics: number of ways to seat 5 children in a line with rules
Let $M$ denote the set of arrangements in which Mike is in the midst. Let $J$ denote the set of arrangements in which Johnny is seated at one of the edges.
Since there are evidently $5!$ arrangements if conditions lack, you are actually looking for: $$5!-|M\cup J|$$
With inclusion/exclusion we find:$$|M\cup J|=|M|+|J|-|M\cap J|=4!+2\cdot4!-2\cdot3!=60$$
so that: $$5!-|M\cup J|=120-60=60$$
Consider two cases -
Case 1)
Johnny sits in the middle. Hence others can sit in any way they want. Hence the number of ways in this case is $4!=24$
Case 2)
Neither Johnny nor Mike sits in the middle.
Now Johnny has only two choices to sit (2nd and 4th) positions. After selecting places for Johnny Mike is left with 3 places to sit because he is not allowed to sit in middle. So he has 3 choices while the rest can be permuted on left three seats. Hence the number of ways in this case are
$$\binom {2}{1}\cdot \binom {3}{1}\cdot 3! =36$$
Hence the total number of ways the students can be seated in a line satisfying the given restrictions are $36+24=60$
Hope it helped.
Let's seat Johnny first then Mike then the others, counting the possibilities in each case
- Johnny in the middle: $1 \times 4 \times 3! = 24$ ways
- Johnny not in the middle: $2 \times 3 \times 3! = 36$ ways
So there are $24+36=60$ possibilities in total