human
Count occurrences of substring X before every occurrence of substring Y in a given string | Function to count occurrences of the string Y in the string S for every occurrence of X in S.
Stores the count of occurrences of X.
Stores the lengths of the three strings.
Traverse the string S.
If the current substring is Y , then increment the value of count by 1.
If the current substring is X , then print the count.
Driver Code"
Solution in Python:
assistant
#Here is code to count occurrences of substring X before every occurrence of substring Y in a given string and the other steps required.
 def countOccurrences ( S , X , Y ) :
	count = 0
	N = len ( S )
	A = len ( X )
	B = len ( Y )
	for i in range ( 0 , N ) :
		if ( S [ i : i + B ] == Y ) :
			count += 1
		if ( S [ i : i + A ] == X ) :
			print ( count , end = " ▁ " )
S = " abcdefdefabc "
X = " abc "
Y = " def "
countOccurrences ( S , X , Y )