human
Count of substrings of a string containing another given string as a substring | Set 2 | Function to count the substrings of containing another given as a sub.
Store length of S.
Store length of T.
Store the required count of substrings.
Store the starting index of last occurence of T in S.
Iterate in range [ 0 , n1 - n2 ].
Check if subfrom i to i + n2 is equal to T.
Check if subfrom i to i + n2 is equal to T.
Mark chk as false and break the loop.
If chk is true.
Add ( i + 1 - last ) * ( n1 - ( i + n2 - 1 ) ) to answer.
Update the last to i + 1.
Prthe answer.
Driver code.
Function Call"
Solution in Python:
 Can you provide a code to count of substrings of a string containing another given string as a substring and the other steps required?
assistant
#Here is code to count of substrings of a string containing another given string as a substring and the other steps required.
 def findOccurrences ( S , T ) :
	n1 = len ( S )
	n2 = len ( T )
	ans = 0
	last = 0
	for i in range ( n1 - n2 + 1 ) :
		chk = True
		for j in range ( n2 ) :
			if ( T [ j ] != S [ i + j ] ) :
				chk = False
				break
		if ( chk ) :
			ans += ( i + 1 - last ) * ( n1 - ( i + n2 - 1 ) )
			last = i + 1
	print ( ans )
if __name__ == ' _ _ main _ _ ' :
	S , T = " dabc " , " ab "
	findOccurrences ( S , T )