Say you have two strings $A = a$ and $B = b$. Now, how do I come up with an expression that gives me the number of substrings of $C = abaa$ that contain atleast one occurrence of both $A$ and $B$?
The number of substrings of $C$ that contain both $A$ and $B$ are:
$ab$
$ba$
$baa$
$aba$
$abaa$
How do I model this in combinatorics?