Dear student
Let the 4 balls be of colors red, blue, green and yellow R,B,G and Y
and the four boxes be of the same four color R,B,G and Y
Total number of ways in which 4 balls can be placed in them will be factorial of 4=24
as of pattern
RBGY, RBYG.RYGB,RYBG,RGYB.RGBY
six for starting with R
four colors, so 24 ways
of 24, there will be only one cases, when balls of same color are in same color box
remaining ways = 24-1=23
Regards