How many permutations of letters ABCDEFG contain the strings ABC and CDE

For this problem, I understand how to find something like how many strings contain the string BA and GF. I just look at the set of letters like this:

{BA, GF, C, D, E}

and since I have 5 distinct elements I can calculate the number of permutations with 5!.

However, I am not sure what to do when the two strings overlap such as the number of permutations which contain the string ABC and CDE or CBA BED.

• Break it into steps. How many strings with $ABC$ are there (ignoring whether or not CDE is present). How many with $CDE$? Finally, how many with $ABCDE$? Use inclusion-exclusion to finish. $|X\cup Y| = |X|+|Y|-|X\cap Y|$ – JMoravitz Feb 18 '15 at 1:18
• Shouldn't ABCDE be one element? – Waffle Feb 18 '15 at 1:20
• @Waffle Looks like you are right. Treating it as {abcde, f, g} and thus using 3! gave me the correct answer. Thanks! – James Hogle Feb 18 '15 at 1:25
• @Waffle I guess this is because the only possible way to have ABC and CDE would be the string ABCDE right? – James Hogle Feb 18 '15 at 1:31
• yeah, add details whether ABC & CDE appears simultaneously or not – Bhaskara-III Dec 11 '16 at 12:37

If not contiguous, there are $\binom75=21$ ways to pick the spots of ABCDE, then two ways to arrange the F and G for each of these. Thus the answer is 42 in that case.